CONTENT
1 EXPERIMENT-1(a)--Controlling Actuators through serial monitor.
Experiment-1(b)--Creating different LED patterns and controlling them using Push button switches.
Experiment-1(c)--Controlling servo motor with help of joystick.
2 EXPERIMENT-2-Calculating distance to an object with help of an ultrasonic sensor and display it on LCD.
3 EXPERIMENT-3(a)--Controlling actuators relay state based on ambient light level using LDR sensor.
Experiment-3(b)--Basic Burglar alarm security system with the help of PIR sensor and buzzer.
Experiment-3(c)--Displaying humidity and temperature values on LCD.
5 EXPERIMENT-5--Upload humidity and temperature data to ThingSpeak, periodically logging ambient
level to ThingSpeak.
EXPERIMENT-1(a)
What is a Buzzer?
An audio signalling device like a beeper or buzzer may be electromechanical or piezoelectric or mechanical
type. The main function working of this is to convert the electrical signal to sound. Generally, it is powered
through DC voltage and used in timers, alarm devices, printers, computers, etc.
Interfacing on AcenAAr IOT trainer kit-
*Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and UPLOAD the
written C++ code using Arduino IDE.
*Connection of the peripherals: Connect the Buzzer module (C) to the ESP32 IoT Module “GPIO”
#define Buzzer 19
void setup() {
Serial.begin(9600);
pinMode(Buzzer, OUTPUT); // set the digital pin as output:
}
void loop() {
if (Serial.available())
{
String command = Serial.readStringUntil('\n');
int myInt = command.toInt();
Serial.println(myInt);
if (myInt== 1)
{
digitalWrite(Buzzer, HIGH); // turn on LED
Serial.println("Buzzer ON");
}
else if (myInt == 0)
{
digitalWrite(Buzzer, LOW); // turn off LED
Serial.println("Buzzer OFF");
}
}
}
Output:
EXPERIMENT-1(b)
What Exactly is an LED?
An LED is a type of diode that turns electrical energy into light. Basically, an LED is an electrical component that
emits light when electricity flows through in one direction. LED is an acronym standing for ‘Light Emitting Diode’.
5mm LEDs also run at much lower drive currents, maxing out at around 30mA. LEDs emits the different colours.
The symbol and model is given below.
Interfacing on AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT module. and UPLOAD the written C++
code using Arduino IDE.
• Connection of the peripherals: Connect the logic (J) to the ESP-32 Module “LEDS”.
Connect the logic (M) to the ESP-32 Module “keyboard”.
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {32, 33, 25, 26}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {27, 14, 12}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const int pins[8] = {15,2,4,16,17,5,18,19};
int counterValue = 1;
int rightShiftValue = 0;
int andMask;
int extractLSB;
int n = 0;
void setup() {
//Serial.begin(9600);
for(int ii = 0; ii < 8; ii++)
pinMode(pins[ii], OUTPUT);
allOff();
}
void loop() {
char key = keypad.getKey();
if (key){
Serial.println(key);
switch(key){
case '1':
allOn();
break;
case '2':
allOff();
break;
case '3':
allOff();
for(int ii = 1; ii <= 5;ii++)
blinkAll();
break;
case '5':
allOff();
binaryCounter();
break;
}
}
}
void allOff()
{
for(int ii = 0;ii < 8; ii++){
//rightShiftValue = counterValue >> ii;
// extractLSB = rightShiftValue & 0x1;
//if(extractLSB == 1)
//digitalWrite(pins[ii], 0);
//else
digitalWrite(pins[ii], 1);
}
}
void allOn()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 0);
}
}
void blinkAll()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 1);
}
delay(500);
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 0);
}
delay(500);
}
void ledWalk()
{
for(int ii = 0;ii < 8; ii++){
digitalWrite(pins[ii], 0);
delay(70);
}
for(int ii = 0;ii < 8; ii++){
delay(70);
digitalWrite(pins[ii], 1);
}
}
void driveCounter(int counterValue)
{
int rightShiftValue, extractLSB;
for(int ii = 0;ii < 8; ii++){
rightShiftValue = counterValue >> ii;
extractLSB = rightShiftValue & 0x1;
if(extractLSB == 1)
digitalWrite(pins[ii], 0);
else
digitalWrite(pins[ii], 1);
}
}
void binaryCounter()
{
for(int ii = 1; ii <= 255; ii++){
driveCounter(ii);
delay(100);
}
}
Output :
EXPERIMENT-1(c)
JOY STICK:
A joystick is an input device that can be used for controlling the movement of the cursor or a pointer in a
computer device. The pointer/cursor movement is controlled by a lever on the joystick. The input device is
mostly used for gaming applications and, sometimes, in graphics applications. A joystick also can be helpful
as an input device for people with movement disabilities.
SERVO MOTOR:
The servo motor is an assembly of four things: a normal DC motor, a gear reduction unit, a position-sensing
device, and a control circuit The DC Servo motor is connected with a gear mechanism that provides
feedback to a position sensor which is mostly a potentiometer.
Servo Motor consists of a DC Motor, a Gear system, a position sensor, and a control circuit. The Gear and
shaft assembly connected to the DC motors lower this speed into sufficient speed and higher torque. The
position sensor senses the position of the shaft from its definite position and feeds the information to the
control circuit.
Interfacing on AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and UPLOAD the
written C++ code using Arduino IDE.
• Connection of the peripherals: Connect the (X3) to the ESP-32 Module “ADC”. Connect the Servo (A) to
the ESP-32 Module “Ultrasonic”.
#define joyX 34
#define joyY 33
#include <Servo_ESP32.h>
static const int servoPin = 23;
Servo_ESP32 servo1;
int pos=0;
int xValue,yValue;
void setup() {
Serial.begin(115200);
Serial.println("Joy Stick in IDLE State");
servo1.attach(servoPin);
}
void loop()
{
xValue = analogRead(joyX);
yValue = analogRead(joyY);
Serial.print(xValue);
Serial.println(yValue);
if(yValue == 0 && xValue < 3200 )
{
for (pos = 180; pos >= 0; pos -= 1)
{
servo1.write(pos);
delay(20);
Serial.println("Right!!!");
}
}
else if(xValue == 0 && yValue <= 3000)
{
Serial.println("Up!!!");
}
else if(xValue <= 400 && yValue ==4095)
{
for (pos = 0; pos <= 180; pos += 1)
{
servo1.write(pos);
delay(20);
Serial.println("Left!!!");
}
}
else if(xValue == 4095 && yValue == 4095){
Serial.println("Down!!!!");
}else{
Serial.println("Idle State");
}
delay(1000);
}
Output :
EXPERIMENT-2
Ultrasonic:
This is a simple and easy to use ultrasonic sensor. It can detect objects Infront of it within a range of 2-
400cm. It is the perfect sensor to use in robotics, obstacle detection, etc. It has a wide beam angle unlike IR
Sensors, which enables it to detect obstacles withing a wide angle. Signals can be read from the 4-pin
interface (Vcc, Trig, Echo, Gnd). One pin is used to trigger the ultrasonic transmitter and another one is
used to read the echo.
Interfacing on AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and UPLOAD the
written C++ code using Arduino IDE.
• Connection of the peripherals:
1. Connect the Ultrasonic sensor (H) to the ESP32 IoT Module "Ultrasonic".
2. From Acenaar IoT Kit Display Module(O) to ESP32 IoT Module "LCD".
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16,2);
#define echoPin 39 // attach pin D5 Arduino to pin Echo of HC-SR04
#define trigPin 23 //attach pin D4 Arduino to pin Trig of HC-SR04
// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
void setup() {
lcd.init();
lcd.backlight();
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
lcd.setCursor(0, 0);
lcd.print("Distance:");
lcd.setCursor(9,0);
lcd.print(distance);
lcd.setCursor(13,0);
lcd.print("CM");
delay(500);
lcd.clear();
}
Output :
EXPERIMENT-3(a)
Interfacing on AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and UPLOAD the
written C++ code using Arduino IDE.
• Connection of the peripherals:
1. From ESP32 IoT Module “ADC” to Acenaar IoT Kit LDR(L)
2. From ESP32 IoT Module “GPIO” to Acenaar IoT Kit RELAY(B)
3.from Esp32 IOT Module “LCD” to Acenaar IOT kit Display unit (O)
#define Relay 19
#define LIGHT_SENSOR_PIN 34 // ESP32 pin GIOP36 (ADC0)
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
void setup() {
// initialize serial communication at 9600 bits per second:
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(Relay,OUTPUT);
}
void loop() {
// reads the input on analog pin (value between 0 and 4095)
int analogValue = analogRead(LIGHT_SENSOR_PIN);
Serial.print("Analog Value = ");
Serial.print(analogValue);// the raw analog reading
lcd.print("Light Intensity");
lcd.setCursor(0,1);
lcd.print(analogValue);
// We'll have a few threshholds, qualitatively determined
if (analogValue < 500)
{
Serial.println(" Relay ON");
digitalWrite(Relay,LOW);
}
else
{
Serial.println(" Relay OFF");
digitalWrite(Relay,HIGH);
}
delay(1000);
lcd.clear();
}
Output :
EXPERIMENT-3(b)
Interfacing AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT module available on Acenaar IoT kit, and UPLOAD the written
C++ code using Arduino IDE.
• Connection of the peripherals:
1. From ESP32 IoT Module “ADC” to Acenaar IoT Kit PIR(G)
2. From ESP32 IoT Module “GPIO” to Acenaar IoT Kit Buzzer(C)
const int Buzzer =19; // the pin that the LED is atteched to
const int sensor = 34; // the pin that the sensor is atteched to
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(Buzzer, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
Serial.println(val);
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(Buzzer, HIGH); // turn LED ON
Serial.println("Motion detected!");
delay(1000);
}
else {
digitalWrite(Buzzer, LOW);
Serial.println("Motion Not detected!");// turn LED OFF
delay(1000); // delay 200 milliseconds
}
}
Output :
EXPERIMENT-3(c)
Interfacing on AcenAAr IOT trainer kit-
• Connect the micro-USB cable to the ESP-32 IOT Module available on Acenaar IoT kit, and UPLOAD the
written C++ code using Arduino IDE.
• Connection of the peripherals:
1. From Acenaar IoT Kit Display Unit(O) to ESP32 IoT Module "LCD".
2. From ESP32 IoT Module "GPIO "to Acenaar IoT Kit "DHT 11"(I).
#include "DHT.h"
#define DHTPIN 19 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16,2);
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
lcd.setCursor(0,0);
lcd.print("Temp");
lcd.setCursor(5,0);
lcd.print((char)223);
lcd.setCursor(6,0);
lcd.print("C");
lcd.setCursor(9,0);
lcd.print("Humi %");
lcd.setCursor(0,1);
lcd.print(temperature);
lcd.setCursor(9,1);
lcd.print(humidity);
}
Output :
EXPERIMENT-5
Interfacing the DHT-11
• Connect the micro-USB cable to the ESP-32 IOT Mod and UPLOAD the written C++ code using Arduino IDE.
• Connection of the peripherals: Connect the DHT-11 module (I) to the ESP-32 “GPIO”.
#include <WiFi.h>
#include "ThingSpeak.h"
#include "DHT.h"
#define DHTPIN 19 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "ACENAARTECHNOLOGY"; // your network SSID (name)
const char* password = "123456789"; // your network password
WiFiClient client;
unsigned long myChannelNumber = 1746705;
const char * myWriteAPIKey = "N0XKWYKGYZ75KC2S";
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;
// Variable to hold temperature readings
float temperatureC;
float humidity;
//uncomment if you want to get temperature in Fahrenheit
//float temperatureF;
// Create a sensor object
//BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)
void readdht(){
if (isnan(humidity) || isnan(temperatureC) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
}
void setup() {
Serial.begin(115200); //Initialize serial
readdht();
dht.begin();
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
if ((millis() - lastTime) > timerDelay) {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
delay(5000);
}
Serial.println("\nConnected.");
}
temperatureC = dht.readTemperature();
Serial.print("Temperature (ºC): ");
Serial.println(temperatureC);
humidity = dht.readHumidity();
Serial.print("Humidity (%): ");
Serial.println(humidity);
//uncomment if you want to get temperature in Fahrenheit
/*temperatureF = 1.8 * bme.readTemperature() + 32;
Serial.print("Temperature (ºC): ");
Serial.println(temperatureF);*/
// set the fields with the values
ThingSpeak.setField(1, temperatureC);
//ThingSpeak.setField(1, temperatureF);
ThingSpeak.setField(2, humidity);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up
to 8 different
// pieces of information in a channel. Here, we write to field 1.
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
lastTime = millis();
}
}
Output :