0% found this document useful (0 votes)
22 views5 pages

Particle count detection using Sharp GP2Y1010AU0F

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Particle count detection using Sharp GP2Y1010AU0F

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Particle count detection using Sharp GP2Y1010AU0F

sensor with NodeMCU ESP8266 Readings will be sent to a


mobile phone through Telegram.
1. Hardware Connections

Components Needed:

 Sharp GP2Y1010AU0F dust sensor


 NodeMCU ESP8266
 220Ω resistor
 150Ω resistor
 10kΩ resistor (optional, for additional filtering)
 Capacitor (0.1 µF)
 Breadboard and jumper wires

Connections:

 Sharp GP2Y1010AU0F Pins:


o VLED (Pin 1): Connect to 5V.
o LED-GND (Pin 2): Connect to GND.
o LED (Pin 3): Connect to GPIO D2 through a 150Ω resistor (to control the
LED).
o S-GND (Pin 4): Connect to GND.
o Vo (Pin 5): Connect to NodeMCU’s A0 pin through a voltage divider
(consisting of 220Ω and 150Ω resistors) to keep the voltage safe for the analog
input.
o VCC (Pin 6): Connect to 5V.

Note: The NodeMCU’s analog pin can only read up to 3.3V, while the sensor’s output can
reach 5V, hence the voltage divider.
2. Code for NodeMCU ESP8266

The code uses the Telegram bot API to send dust concentration readings to a mobile phone.

Libraries Needed:

 ESP8266WiFi.h: To connect to WiFi.


 WiFiClientSecure.h: To securely connect to Telegram servers.
 ESP8266HTTPClient.h: To send HTTP requests to Telegram API.

Codes ;

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

#include <ESP8266HTTPClient.h>

// WiFi credentials

const char* ssid = "YOUR_WIFI_SSID";

const char* password = "YOUR_WIFI_PASSWORD";

// Telegram bot details

const String BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN";

const String CHAT_ID = "YOUR_TELEGRAM_CHAT_ID";

// Hardware definitions

#define LED_PIN D2

#define ANALOG_PIN A0

void setup() {

// Setup serial communication for debugging

Serial.begin(115200);

// Set the LED control pin as output

pinMode(LED_PIN, OUTPUT);

// Connect to WiFi
Serial.print("Connecting to WiFi...");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("Connected!");

void loop() {

// Read dust sensor value

digitalWrite(LED_PIN, LOW); // Turn on the LED

delayMicroseconds(280);

int rawValue = analogRead(ANALOG_PIN);

delayMicroseconds(40);

digitalWrite(LED_PIN, HIGH); // Turn off the LED

delay(9680); // Rest of the sampling period

// Convert raw value to voltage

float voltage = rawValue * (5.0 / 1023.0);

// Convert voltage to dust concentration (in mg/m³)

float dustConcentration = (voltage - 0.6) * 0.5;

Serial.print("Dust concentration: ");

Serial.print(dustConcentration);

Serial.println(" mg/m³");

// Send data to Telegram

sendTelegramMessage(dustConcentration);
delay(10000); // Wait for 10 seconds before the next reading

void sendTelegramMessage(float value) {

if (WiFi.status() == WL_CONNECTED) {

WiFiClientSecure client;

client.setInsecure(); // For non-verified SSL certificates

HTTPClient https;

String url = "https://api.telegram.org/bot" + BOT_TOKEN + "/sendMessage?chat_id=" + CHAT_ID +


"&text=Dust Concentration: " + String(value) + " mg/m³";

https.begin(client, url);

int httpCode = https.GET();

if (httpCode > 0) {

String payload = https.getString();

Serial.println("Telegram response: " + payload);

} else {

Serial.println("Error on HTTP request");

https.end();

} else {

Serial.println("WiFi not connected!");

}
3. Setting Up Telegram Bot

1. Create a Telegram Bot:


o Open Telegram and search for "BotFather".
o Use the command /newbot to create a bot and get a Bot Token. This token is
used to send messages via the Telegram API.
2. Get Your Chat ID:
o Open a web browser and go to
https://api.telegram.org/bot<YourBotToken>/getUpdates (replace
<YourBotToken> with your actual bot token).
o Send a message to your bot in Telegram. Then reload the page, and you’ll see
JSON data with your chat ID.
3. Use Bot Token and Chat ID in Your Code:
o Replace YOUR_TELEGRAM_BOT_TOKEN and YOUR_TELEGRAM_CHAT_ID in the
code with the values you received.

Explanation

 The NodeMCU controls the LED of the GP2Y1010AU0F, taking a reading after a
280µs delay to measure dust particles accurately.
 The voltage reading is converted to dust concentration (approximated in mg/m³).
 Every 10 seconds, a message is sent to a predefined Telegram chat containing the dust
concentration reading.

You might also like