Search Results
163 results found with an empty search
- Hand Gesture Controlled 2WD using Accelerometer, RF(433 Mhz ), Decoder and Encoder
A simple Arduino based RF controlled robot that can be driven remotely. The RF remote control provides the advantage of a good controlling range (up to 100 metres with proper antenna). In this project we have used hand motion to drive the robot. For this purpose we have used accelerometer (ADXL345) which works on acceleration. A gesture controlled robot is controlled by using hand in place of any other method like buttons or joystick. Here one only needs to move hand to control the robot. A transmitting device is used in your hand which contains RF Transmitter and accelero-meter. This will transmit command to robot so that it can do the required task like moving forward, reverse, turning left, turning right and stop. All these tasks will be performed by using hand gesture. Here the most important component is accelerometer. Accelerometer is a 3 axis acceleration measurement device with +-3g range. This device is made by using polysilicon surface sensor and signal conditioning circuit to measure acceleration. The output of this device is Analog in nature and proportional to the acceleration. This device measures the static acceleration of gravity when we tilt it. And gives an result in form of motion or vibration. Components Required 433 MHz RF Transmitter and Receiver Module HT12D Decoder Module HT12E EncoderModule Push Buttons (4 Nos) 4 Channel Relay Module Arduino Uno ADXL345 ADXL345 Tripple Axis Accelerometer Board is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g. Digital output data is format as 16-bit twos complement and is accessible through either an SPI (3- or 4-wire) or I2C digital interface. The ADXL345 Tripple Axis Accelerometer Board is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0°. Features : Ultra-Low Power: 40µA in measurement mode, 0.1µA in standby@ 2.5V. Free-Fall Detection. Tap/Double Tap Detection. Flexible interrupt modes mappable to either interrupt pin Measurement ranges selectable via serial command Bandwidth selectable via serial command Wide temperature range (−40°C to +85°C). 10,000 g shock survival. Support 5V/3.3V voltage input, onboard RT9161 power chip, lower pressure drop faster than 1117, the faster load speed of response, very suitable for high-noise power supply environment. User-selectable resolution Fixed 10-bit resolution. Full resolution, where resolution increases with G range, up to 13-bit resolution at ±16 g (maintaining 4 mg/LSB scale factor in all G ranges). Explanation Gesture Controlled Robot is divided into two sections: Transmitter part Receiver part In transmitter part an accelerometer and a RF transmitter unit is used. As we have already discussed that accelerometer gives an analog output so here we need to convert this analog data in to digital. For this purpose we have used 4 channel comparator circuit in place of any ADC. By setting reference voltage we gets a digital signal and then apply this signal to HT12E encoder to encode data or converting it into serial form and then send this data by using RF transmitter into the environment. At the receiver end we have used RF receiver to receive data and then applied to HT12D decoder. This decoder IC converts received serial data to parallel and then read by using arduino. According to received data we drive robot by using two DC motor in forward, reverse, left, right and stop direction. operation Gesture controlled robot moves according to hand movement as we place transmitter in our hand. When we tilt hand in front side, robot start to moving forward and continues moving forward until next command is given. When we tilt hand in backward side, robot change its state and start moving in backwards direction until other command is given. When we tilt it in left side Robot get turn left till next command. When we tilt hand in right side robot turned to right. And for stopping robot we keeps hand in stable. Circuit Connection Transmitter circuit Receiver circuit Arduino Pin D2 to D5 are Connected to AD8 through AD11 of Decoder HT12D Module. Arduino Pin D8 and D9 are Connected to Left Motor Arduino Pin D10 and D11 are Connected to Right Motor Subscribe and Download code. Arduino Code: //RF Robot int sw1 =2; int sw2 =3; int sw3 =4; int sw4 =5; int out1=8; int out2=9; int out3=10; int out4=11; void setup() { pinMode(sw1,INPUT); pinMode(sw2,INPUT); pinMode(sw3,INPUT); pinMode(sw4,INPUT); pinMode(out1,OUTPUT); pinMode(out2,OUTPUT); pinMode(out3,OUTPUT); pinMode(out4,OUTPUT); } void loop() { if ((digitalRead(sw1)==LOW) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==HIGH)) { fwd(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==LOW) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==HIGH)) { bwk(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==LOW) && (digitalRead(sw4)==HIGH)) { lft(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==LOW)) { rgt(); } else { digitalWrite(out1,LOW); digitalWrite(out2,LOW); digitalWrite(out3,LOW); digitalWrite(out4,LOW); } } void fwd() { digitalWrite(out1,HIGH); digitalWrite(out2,LOW); digitalWrite(out3,HIGH); digitalWrite(out4,LOW); } void bwk() { digitalWrite(out1,LOW); digitalWrite(out2,HIGH); digitalWrite(out3,LOW); digitalWrite(out4,HIGH); } void lft() { digitalWrite(out1,HIGH); digitalWrite(out2,LOW); digitalWrite(out3,LOW); digitalWrite(out4,LOW); } void rgt() { digitalWrite(out1,LOW); digitalWrite(out2,LOW); digitalWrite(out3,HIGH); digitalWrite(out4,LOW); }
- RF Encoder and Decoder Controlled 4 Channel Relay
This tutorial to learn, One of the easiest and cheapest ways to implement wireless communication is using RF Module (Radio Frequency Module). The transmitter circuit is built encoder HT12E Module , 433MHz RF transmitter module (TX). The receiver circuit is built around Arduino UNO board, decoder HT12D Module, 433MHz RF receiver module (RX), 4 Channel Relay Board. Refer previous tutorial for RF encoder and decoder Interface. https://www.dofbot.com/post/rf-encoder-and-decoder-interface-with-arduino Subscribe and Download code. Components required 433 MHz RF Transmitter and Receiver Module HT12D Decoder Module HT12E EncoderModule Push Buttons (4 Nos) 4 Channel Relay Module Arduino Uno Circuit Connection Transmitter circuit Push Button Switches S1, S2, S3 and S4 are interfaced with AD8 through AD11 of encoder HT12E Module. Receiver circuit Arduino Pin D2 to D5 are Connected to AD8 through AD11 of Decoder HT12D Module. Arduino Pin D8 to D11 are Connected to LED or Relay. Subscribe and Download code. Subscribe and Download code. arduino code // WWW.DOFBOT.COM const int Switch1 = 2, Relay1 = 8; int state1 = 0, Relay1state=0; const int Switch2 = 3, Relay2 = 9; int state2 = 0, Relay2state=0; const int Switch3 = 4, Relay3 = 10; int state3 = 0, Relay3state=0; const int Switch4 = 5, Relay4 = 11; int state4 = 0, Relay4state=0; void setup() { pinMode(Switch1, INPUT); pinMode(Switch2, INPUT); pinMode(Switch3, INPUT); pinMode(Switch4, INPUT); pinMode(Relay1, OUTPUT); pinMode(Relay2, OUTPUT); pinMode(Relay3, OUTPUT); pinMode(Relay4, OUTPUT); Serial.begin(9600); } void loop() { if (state1 == 0 && digitalRead(Switch1) == HIGH) { state1 = 1; Relay1state=!Relay1state; } if (state1 == 1 && digitalRead(Switch1) == LOW) { state1 = 0; } digitalWrite(Relay1, Relay1state); //// if (state2 == 0 && digitalRead(Switch2) == HIGH) { state2 = 1; Relay2state=!Relay2state; } if (state2 == 1 && digitalRead(Switch2) == LOW) { state2 = 0; } digitalWrite(Relay2, Relay2state); /// if (state3 == 0 && digitalRead(Switch3) == HIGH) { state3 = 1; Relay3state=!Relay3state; } if (state3 == 1 && digitalRead(Switch3) == LOW) { state3 = 0; } digitalWrite(Relay3, Relay3state); //// if (state4 == 0 && digitalRead(Switch4) == HIGH) { state4 = 1; Relay4state=!Relay4state; } if (state4 == 1 && digitalRead(Switch4) == LOW) { state4 = 0; } digitalWrite(Relay4, Relay4state); }
- RF Encoder and Decoder interface with Arduino
This tutorial to learn, One of the easiest and cheapest ways to implement wireless communication is using RF Module (Radio Frequency Module). The transmitter circuit is built encoder HT12E Module , 433MHz RF transmitter module (TX) and a few discrete components. The receiver circuit is built around Arduino UNO board, decoder HT12D Module, 433MHz RF receiver module (RX), 4 LED and a few discrete components. Components required 433 MHz RF Transmitter and Receiver Module HT12D Decoder Module HT12E EncoderModule Push Buttons (4 Nos) LEDs (4 Nos) Arduino Uno 433MHz RF Transmitter and Receiver Module: This hybrid RF Transceiver Module provides a complete RF transmitter and receiver module solution which can be used to transmit data at up to 3KHz from any standard CMOS/TTL source. The transmitter module is very simple to operate and offers low current consumption (typical. 11mA). Data can be supplied directly from a microprocessor or encoding device, thus keeping the component count down and ensuring a low hardware cost. The RX – ASK is an ASK Hybrid receiver module. The RF Transmitter Receiver Module is an effective low-cost solution for using 433 MHz. The TX-ASK is an ASK hybrid transmitter module. TX-ASK is designed by the saw resonator, with an effective low cost, small size and simple to use for designing. Specifications of 433MHz RF Transmitter Receiver Wireless Module: Range in open space(Standard Conditions) : 100 Meters RX Receiver Frequency : 433 MHz RX Typical Sensitivity : 105 Dbm RX Supply Current : 3.5 mA RX IF Frequency : 1MHz RX Operating Voltage : 5V TX Frequency Range : 433.92 MHz TX Supply Voltage : 3V ~ 6V TX Out Put Power : 4 ~ 12 Dbm Features of 433MHz RF Transmitter Receiver Wireless Module: Low Power Consumption Easy For RF based Application Complete Radio Transmitter Transmit Range Up To 50m CMOS / TTL Input No Adjustable Components Very Stable Operating Frequency Low Current Consumption (Typ 11mA) Wide Operating Voltage ASK Modulation RF Encoder Decoder Module Board The module is a pair of Encoder & Decoder Boards. The entire module is quite easy to use and is compatible with most of the old and new versions of Arduino/Raspberry Pi, PIC boards or projects. Features RF Encoder Decoder Module Board: Easy interfacing with the RF modules, using the female headers for placing the modules. Breakout pins for connecting to the microcontroller. DIP Switch for Address Selection (when multiple modules are used at one location) Status LED for valid transmit. Supports both ASK, FSK RF modules Small size, high quality PCB. 433MHz RF Transmitter and Receiver with RF Encoder Decoder Module: Circuit Connection Transmitter circuit Push Button Switches S1, S2, S3 and S4 are interfaced with AD8 through AD11 of encoder HT12E Module. Receiver circuit Arduino Pin D2 to D5 are Connected to AD8 through AD11 of Decoder HT12D Module. Arduino Pin D8 to D11 are Connected to LED or Relay. Subscribe and Download code. Subscribe and Download code. arduino code //// WWW.DOFBOT.COM int sw1 =2; int sw2 =3; int sw3 =4; int sw4 =5; int out1=8; int out2=9; int out3=10; int out4=11; void setup() { pinMode(sw1,INPUT); pinMode(sw2,INPUT); pinMode(sw3,INPUT); pinMode(sw4,INPUT); pinMode(out1,OUTPUT); pinMode(out2,OUTPUT); pinMode(out3,OUTPUT); pinMode(out4,OUTPUT); } void loop() { if ((digitalRead(sw1)==LOW) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==HIGH)) { RELAY1(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==LOW) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==HIGH)) { RELAY2(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==LOW) && (digitalRead(sw4)==HIGH)) { RELAY3(); } else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==HIGH) && (digitalRead(sw3)==HIGH) && (digitalRead(sw4)==LOW)) { RELAY4(); } else { digitalWrite(out1,LOW); digitalWrite(out2,LOW); digitalWrite(out3,LOW); digitalWrite(out4,LOW); } } void RELAY1() { digitalWrite(out1,HIGH); digitalWrite(out2,LOW); digitalWrite(out3,LOW); digitalWrite(out4,LOW); } void RELAY2() { digitalWrite(out1,LOW); digitalWrite(out2,HIGH); digitalWrite(out3,LOW); digitalWrite(out4,LOW); } void RELAY3() { digitalWrite(out1,LOW); digitalWrite(out2,LOW); digitalWrite(out3,HIGH); digitalWrite(out4,LOW); } void RELAY4() { digitalWrite(out1,LOW); digitalWrite(out2,LOW); digitalWrite(out3,LOW); digitalWrite(out4,HIGH); }
- Web Server Based Metal Touch Detector
Learn the interfacing Metal Touch Sensor Module KY-036 in ESP8266 12E. The touch sensor will generate certain output on touching metal spike of the sensor. Measured input from the Sensor is then fed to the amplifier. Amplifier then sends analog / Digital data to the analog / Digital output pin of the module. In this, we are going to interface, LCD, HTTP server for Real time data logger, Buzzer using the Metal Touch Sensor Module KY-036 / KSP13 with NodeMCU esp8266 12E. Circuit Diagram Components required nodeMCU ESP8266 12E KY-036 Metal Touch Sensor LCD 16x2 I2C Buzzer KY-036 Metal Touch sensor KY-036 Metal touch sensor module Very simple – the touch sensor (KSP13-NPN Epitaxial Silicon Darlington Transistor) will generate an output when the metal leg of the KSP13 is touched. This is then fed to the LM386 amplifier. The amplifier then sends the data to the digital output pin of the module. LED1: Shows that the sensor is supplied with voltage LED2: Shows that the sensor detects a magnetic field Outputs a signal if the metal pike of the Sensor was touched. You can adjust the sensitivity of the sensor with the controller. Digital Out: At the moment of contact detection, a signal will be outputted. Analog Out: Direct measuring value of the sensor unit. The sensor has 3 main components on its circuit board. First, the sensor unit at the front of the module which measures the area physically and sends an analog signal to the second unit, the amplifier. The amplifier amplifies the signal, according to the resistant value of the potentiometer, and sends the signal to the analog output of the module.The third component is a comparator which switches the digital out and the LED if the signal falls under a specific value. You can control the sensitivity by adjusting the potentiometer. The signal will be inverted; that means that if you measure a high value, it is shown as a low voltage value at the analog output. Buzzer Sounds when touched the Metal touch sensor. Positive: Identified by (+) symbol or longer terminal lead. Can be Connected to NodeMCU pin D4. Negative: Identified by short terminal lead. Typically connected to the ground of the circuit. Rated Voltage: 6V DC Operating Voltage: 4-8V DC Rated current: <30mA LCD 16x2 (I2C module) This is a 16x2 LCD display screen with I2C interface. It is able to display 16x2 characters on 2 lines, white characters on blue background. This I2C 16x2 Arduino LCD Screen is using an I2C communication interface. It means it only needs 4 pins for the LCD display: VCC, GND, SDA, SCL. Connecting the LCD to NodeMCU Connect the VCC I2C pin to a Vin pin on the NodeMCU. Connect the GND I2C pin to a GND pin on the NodeMCU. Connect the SCL I2C pin to a D1 pin on the NodeMCU. Connect the SDA I2C pin to a D2 pin on the NodeMCU. Installing Libraries LiquidCrystal_I2C.h : you need to Download and install the LiquidCrystal_I2C library. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Subscribe and Download code. Arduino Code #include #include #include const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; //your WIFI PASSWORD #include LiquidCrystal_I2C lcd(0x27,16,2); ESP8266WebServer server(80); //Server on port 80 int buzzer = 2; //Buzzer alarm connected to GPIO-14 or D5 of nodemcu int MetalTouch = 16; //Metal sensor output connected to GPIO-5 or D1 of nodemcu String Message; const char MAIN_page[] PROGMEM = R"=====( Iot Based Metal Touch Detector Real Time Data for Touch Log TimeLog )====="; void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, "text/html", s); //Send web page } void readData() { lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); int state = digitalRead(MetalTouch); //Continuously check the state of Metal sensor delay(500); //Check state of Metal after every half second lcd.setCursor(0,0); lcd.print("Metal Body Scan"); lcd.setCursor(0,1); lcd.print("....No Touch...."); Serial.print(state); if(state == HIGH){ digitalWrite (buzzer, HIGH); //If intrusion detected ring the buzzer lcd.setCursor(0,1); lcd.print(" Body Touched "); delay(1000); digitalWrite (buzzer, LOW); lcd.setCursor(0,1); lcd.print("Sent to HTTP >>>"); delay(1000); Message = "Metal Body Touched"; String data = "{\"Log\":\""+ String(Message) +"\"}"; server.send(200, "text/plane", data); //Send ADC value, temperature and humidity JSON to client ajax request Serial.println("Metal Body Touched"); } } void setup() { Serial.begin(9600); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); Serial.print("Connecting to Wifi Network"); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("Successfully connected to WiFi."); Serial.println("IP address is : "); Serial.println(WiFi.localIP()); lcd.setCursor(0,0); lcd.print(WiFi.localIP()); delay(2000); lcd.clear(); server.on("/", handleRoot); //Which routine to handle at root location. This is display page server.on("/readData", readData); //This page is called by java Script AJAX server.begin(); //Start server Serial.println("HTTP server started"); pinMode(MetalTouch, INPUT); // Metal sensor as input pinMode(buzzer, OUTPUT); // Buzzer alaram as output digitalWrite (buzzer, LOW);// Initially buzzer off } void loop(){ server.handleClient(); //Handle client requests } Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address. After That Open web address and Type IP address in address bar and get result.
- Arduino Based 4DOF Robotic Arm Control
In this tutorial we are going to do is a simple design an Arduino Uno based 4DOF Robotic Arm control using potentiometer. This project will be helpful for beginners who want to learn to develop a Simple Robot (Me arm) in low cost or just want to learn working with Arduino and servo motors. This Arduino Robotic Me Arm can be controlled by four Potentiometer attached to it, each potentiometer is used to control each servo. You can move these servos by rotating the pots to pick some object, with some practice you can easily pick and move the object from one place to another. We have used low torque servos with metal gear here but you can use more powerful servos to pick heavy objects. Circuit Diagram Components Required Arduino Uno Servo Motor MG 90S - 4nos 10K Linear Pot- 4nos 5VDC Power Supply Servo Motor MG-90S A servo motor is a closed-loop system that uses position feedback to control its motion and final position.RC servo motor works on the same principal. It contains a small DC motor connected to the output shaft through the gears. Connecting the Servo Motor to the arduino uno Black wire of servo motor to the GND pin of arduino uno Red wire of servo motor to the 5V pin of arduino uno Orange wire of servo motor to the D5, D6,D7,D8 of arduino uno Robotic Arm: We provide variable voltage at the ADC channels of arduino UNO using Pot. So the digital values of Arduino are under control of user. These digital values are mapped to adjust the servo motor position, hence the servo position is in control of user and by rotating these Pots user can move the joints of Robotic arm. Installing the Arduino_Library No special Library require for this project. Subscribe and Download code. arduino code #include Servo servo0; Servo servo1; Servo servo2; Servo servo3; int sensorvalue0; int sensorvalue1; int sensorvalue2; int sensorvalue3; void setup() { Serial.begin(9600); pinMode(A0,INPUT); pinMode(5,OUTPUT); servo0.attach(5); pinMode(A1,INPUT); pinMode(6,OUTPUT); servo1.attach(6); pinMode(A2,INPUT); pinMode(7,OUTPUT); servo2.attach(7); pinMode(A3,INPUT); pinMode(8,OUTPUT); servo3.attach(8); } void loop() { sensorvalue0 = analogRead(A0); sensorvalue0 = map(sensorvalue0, 0, 1023, 0, 120); // left servo servo0.write(sensorvalue0); // Serial.println (sensorvalue0); sensorvalue1 = analogRead(A1); sensorvalue1 = map(sensorvalue1, 0, 1023, 70, 150); // right servo servo1.write(sensorvalue1); // Serial.println (sensorvalue1); sensorvalue2 = analogRead(A2); sensorvalue2 = map(sensorvalue2, 0, 1023, 20, 160); // center servo servo2.write(sensorvalue2); //Serial.println (sensorvalue2); sensorvalue3 = analogRead(A3); sensorvalue3 = map(sensorvalue3, 0, 1023, 130, 145); // jaw servo servo3.write(sensorvalue3); // Serial.println (sensorvalue3); }
- JoyStick Controlled Relay Board
In this project, we are interfacing Joystick with Arduino simply by controlling four Channel relay Board as per the movement of the Joystick. We have placed 4 relays in the such a way that it represents the direction of the joystick shaft movement. This joystick also has a push button which can be used for various other purposes or can be left idle. The first thing that comes in our mind listening to the word Joystick is the game controller. Yes, it’s exactly the same and can be used for gaming purpose. Apart from gaming, it has many other applications in DIY electronics. This joystick is nothing but a combination of two potentiometers for X and Y plane respectively. It reads the voltage through the potentiometer and gives analog value to the Arduino, and the analog value changes as we move the joystick shaft (which is simply the potentiometer pointer). Circuit Diagram Components Required Arduino UNO PS2 Joystick Module Breakout Sensor 4 Channel Relay Board Jumper wires JoyStick This is JoyStick Module PS2 Breakout Sensor very similar to the ‘analog’ joysticks on PS2 (PlayStation 2) controllers. Directional movements are simply two potentiometers – one for each axis. Pots are ~10k each. This joystick also has a select button that is actuated when the joystick is press down. With the help of this Joystick Module, you can measure position coordinates on the X and Y axis by moving the “hat”. It also contains a switch that is press-able by pushing the “hat”.It also contains a switch that is press-able by pushing the “hat” down. Similar to the XBOX controller. The X and Y axes are two 10k potentiometers which control 2D movement by generating analog signals. When the module is in working mode, it will output two analog values, representing two directions. This module uses the 5V power supply, and value, when reading through analog input, would be about 2.5V, a value will increase with joystick movement and will go up till maximum 5V; the value will decrease when the joystick is moved in other direction till 0V. OVERVIEW Dimensions: 40 x 27 x 15 (LxWxH) mm. Weight: 10gm (without Hat). 2.54mm pin interface leads. Operating Voltage: 5V. Long service life and stable performance. Standard interface and electronic building blocks. Widely use in Arduino DIY projects. Applications: 1.As square wave signal generator which generates a square wave signal 2. To provide a signal to the stepping motor driver 3. Adjustable pulse generation for chip use 4. Produce variable pulse signal, the control-related circuit (PWM dimming, speed) Subscribe and Download code. Installing the Arduino_Library No special Library require for this project. Testing of Joystick Arduino code int xPin = A1; int yPin = A0; int buttonPin = 2; int xPosition = 0; int yPosition = 0; int buttonState = 0; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); pinMode(xPin, INPUT); pinMode(yPin, INPUT); //activate pull-up resistor on the push-button pin pinMode(buttonPin, INPUT_PULLUP); // For versions prior to Arduino 1.0.1 // pinMode(buttonPin, INPUT); // digitalWrite(buttonPin, HIGH); } void loop() { xPosition = analogRead(xPin); yPosition = analogRead(yPin); buttonState = digitalRead(buttonPin); Serial.print("X: "); Serial.print(xPosition); Serial.print(" | Y: "); Serial.print(yPosition); Serial.print(" | Button: "); Serial.println(buttonState); delay(100); // add some delay between reads } Result in serial monitor Subscribe and Download code. Main arduino code #define joyX A0 #define joyY A1 int button=2; int buttonState = 0; int buttonState1 = 0; void setup() { //pinMode(7,OUTPUT); pinMode(button,INPUT); digitalWrite(button, HIGH); Serial.begin(9600); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT); pinMode(11,OUTPUT); } void loop() { int xValue = analogRead(joyX); int yValue = analogRead(joyY); Serial.print(xValue); Serial.print("\t"); Serial.println(yValue); buttonState = digitalRead(button); Serial.println(buttonState); if (xValue>=0 && yValue<=10) { digitalWrite(10, HIGH); } else{digitalWrite(10, LOW);} if (xValue<=10 && yValue>=500) { digitalWrite(11, HIGH); } else{digitalWrite(11, LOW);} if (xValue>=900 && yValue>=400) { digitalWrite(9, HIGH); } else{digitalWrite(9, LOW);} if (xValue>=400 && yValue>=900) { digitalWrite(8, HIGH); } else{digitalWrite(8, LOW);} if (buttonState == LOW) { Serial.println("Switch = High"); digitalWrite(8, HIGH); digitalWrite(9, HIGH); digitalWrite(10, HIGH); digitalWrite(11, HIGH); } else{//digitalWrite(7, LOW); } // buttonState1 = digitalRead(7); Serial.println(buttonState1); delay(100); } Result in serial monitor
- Pong Game using dot matrix display 8X8
In this Pong Game project, The dot matrix that we’re going to use in this guide is a 8×8 matrix which means that it has 8 columns and 8 rows, so it contains a total of 64 LEDs. The MAX7219 chip makes it easier to control the dot matrix, by just using 3 digital pins of the Arduino board. You can control more than one matrix at a time. For that you just need to connect them to each other, as they have pins in both sides to extend the dot matrix. Circuit Diagram Components Required 8×8 Dot Matrix with MAX7219 - 1 Arduino UNO Potentiometer 10K ohms Jumper Wires Installing the Arduino_Library Download timer Libray Download Led Control library Subscribe and Download code. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code #include "LedControl.h" #include "Timer.h" #define POTPIN A5 // Potentiometer #define PADSIZE 3 #define BALL_DELAY 200 #define GAME_DELAY 10 #define BOUNCE_VERTICAL 1 #define BOUNCE_HORIZONTAL -1 #define NEW_GAME_ANIMATION_SPEED 50 #define HIT_NONE 0 #define HIT_CENTER 1 #define HIT_LEFT 2 #define HIT_RIGHT 3 //#define DEBUG 1 byte sad[] = { B00000000, B01000100, B00010000, B00010000, B00000000, B00111000, B01000100, B00000000 }; byte smile[] = { B00000000, B01000100, B00010000, B00010000, B00010000, B01000100, B00111000, B00000000 }; Timer timer; LedControl lc = LedControl(12,11,10,1); byte direction; // Wind rose, 0 is north int xball; int yball; int yball_prev; byte xpad; int ball_timer; void setSprite(byte *sprite){ for(int r = 0; r < 8; r++){ lc.setRow(0, r, sprite[r]); } } void newGame() { lc.clearDisplay(0); // initial position xball = random(1, 7); yball = 1; direction = random(3, 6); // Go south for(int r = 0; r < 8; r++){ for(int c = 0; c < 8; c++){ lc.setLed(0, r, c, HIGH); delay(NEW_GAME_ANIMATION_SPEED); } } setSprite(smile); delay(1500); lc.clearDisplay(0); } void setPad() { xpad = map(analogRead(POTPIN), 0, 1020, 8 - PADSIZE, 0); } void debug(const char* desc){ #ifdef DEBUG Serial.print(desc); Serial.print(" XY: "); Serial.print(xball); Serial.print(", "); Serial.print(yball); Serial.print(" XPAD: "); Serial.print(xpad); Serial.print(" DIR: "); Serial.println(direction); #endif } int checkBounce() { if(!xball || !yball || xball == 7 || yball == 6){ int bounce = (yball == 0 || yball == 6) ? BOUNCE_HORIZONTAL : BOUNCE_VERTICAL; #ifdef DEBUG debug(bounce == BOUNCE_HORIZONTAL ? "HORIZONTAL" : "VERTICAL"); #endif return bounce; } return 0; } int getHit() { if(yball != 6 || xball < xpad || xball > xpad + PADSIZE){ return HIT_NONE; } if(xball == xpad + PADSIZE / 2){ return HIT_CENTER; } return xball < xpad + PADSIZE / 2 ? HIT_LEFT : HIT_RIGHT; } bool checkLoose() { return yball == 6 && getHit() == HIT_NONE; } void moveBall() { debug("MOVE"); int bounce = checkBounce(); if(bounce) { switch(direction){ case 0: direction = 4; break; case 1: direction = (bounce == BOUNCE_VERTICAL) ? 7 : 3; break; case 2: direction = 6; break; case 6: direction = 2; break; case 7: direction = (bounce == BOUNCE_VERTICAL) ? 1 : 5; break; case 5: direction = (bounce == BOUNCE_VERTICAL) ? 3 : 7; break; case 3: direction = (bounce == BOUNCE_VERTICAL) ? 5 : 1; break; case 4: direction = 0; break; } debug("->"); } // Check hit: modify direction is left or right switch(getHit()){ case HIT_LEFT: if(direction == 0){ direction = 7; } else if (direction == 1){ direction = 0; } break; case HIT_RIGHT: if(direction == 0){ direction = 1; } else if(direction == 7){ direction = 0; } break; } // Check orthogonal directions and borders ... if((direction == 0 && xball == 0) || (direction == 4 && xball == 7)){ direction++; } if(direction == 0 && xball == 7){ direction = 7; } if(direction == 4 && xball == 0){ direction = 3; } if(direction == 2 && yball == 0){ direction = 3; } if(direction == 2 && yball == 6){ direction = 1; } if(direction == 6 && yball == 0){ direction = 5; } if(direction == 6 && yball == 6){ direction = 7; } // "Corner" case if(xball == 0 && yball == 0){ direction = 3; } if(xball == 0 && yball == 6){ direction = 1; } if(xball == 7 && yball == 6){ direction = 7; } if(xball == 7 && yball == 0){ direction = 5; } yball_prev = yball; if(2 < direction && direction < 6) { yball++; } else if(direction != 6 && direction != 2) { yball--; } if(0 < direction && direction < 4) { xball++; } else if(direction != 0 && direction != 4) { xball--; } xball = max(0, min(7, xball)); yball = max(0, min(6, yball)); debug("AFTER MOVE"); } void gameOver() { setSprite(sad); delay(1500); lc.clearDisplay(0); } void drawGame() { if(yball_prev != yball){ lc.setRow(0, yball_prev, 0); } lc.setRow(0, yball, byte(1 << (xball))); byte padmap = byte(0xFF >> (8 - PADSIZE) << xpad) ; #ifdef DEBUG //Serial.println(padmap, BIN); #endif lc.setRow(0, 7, padmap); } void setup() { // The MAX72XX is in power-saving mode on startup, // we have to do a wakeup call pinMode(POTPIN, INPUT); lc.shutdown(0,false); // Set the brightness to a medium values lc.setIntensity(0, 8); // and clear the display lc.clearDisplay(0); randomSeed(analogRead(0)); #ifdef DEBUG Serial.begin(9600); Serial.println("Pong"); #endif newGame(); ball_timer = timer.every(BALL_DELAY, moveBall); } void loop() { timer.update(); // Move pad setPad(); #ifdef DEBUG Serial.println(xpad); #endif // Update screen drawGame(); if(checkLoose()) { debug("LOOSE"); gameOver(); newGame(); } delay(GAME_DELAY); } Result Here’s the final demonstration of me playing the pong game. Have fun!
- RPM Measurement Using Optical Interrupter Switch
In this project, I will talk about Phototransistor Optical Interrupter Switches (Opto Coupler) Module, how this module works and helps in determining the speed of a rotating object and finally I will show you how to Interface Optical Interrupter Switch Sensor with Arduino and measure the speed of a motor in second , Minute and revolution encoder Slot count. Circuit Diagram: Components Required Arduino Uno Optical Endstop Light Control Limit Optical Switch (H21A1) LCD display 20x4 BO Motor with Revolution Encoder for Measurement Optical Endstop Light Control Limit Optical Switch Actually, This fully assembled plug and play Optical Endstop Light Control Limit Optical Switch is very suitable for your 3D printing or CNC project. The Optical Endstop Switch will immediately output the digital control when the light is blocked and turn the LED on. The optical end-stop is a reliable end-stop / switch solution for any type of 3D printers and other CNC and 3D tools. Using optical transmission principle designed, no loss, no noise, and longer service life reached more than one hundred thousand times. H21A1 Optical Interrupter The H21A and H22A series of opaque photointerrupters are single channel switches consisting of a Gallium Arsenide infrared emitting diode and a NPN silicon phototransistor mounted in polycarbonate housing. The package is designed to optimize the mechanical resolution, coupling efficiency, ambient light rejection, cost and reliability. Operating on the principle that objects opaque to infrared will interrupt the transmission of light between an infrared emitting diode and a photo sensor switching the output from an "ON" state to an "OFF" state. The main aim of this project is to measure the rotational speed of a motor using an Arduino. In order to measure the speed of a rotating device like a simple DC Motor for example, we need a special device like a speed sensor. The combination of BO motor + wheel and a encoder disc with 20 slots and 24mm outer diameter along with encoder slit sensor module for detecting the number of counts moved by the wheel. The digital output can be fed to a microcontroller for find the rpm of the bo motor. The encoder wheel consists of 20 holes (this number becomes important in the program part These rotary encoders fit Motors and Encoder Counters. Use them to feedback speed and distance, or make your own anemometer or wind speed meter.. Installing the Arduino_Library LiquidCrystal_I2C.h : you need to Downloadand install the LiquidCrystal_I2C library. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code #include LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display int sensor = 11; unsigned long start_time = 0; unsigned long end_time = 0; int steps=0; float steps_old=0; float temp=0; float RPS=0; float RPM=0; void setup() { Serial.begin(9600); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); pinMode(sensor,INPUT_PULLUP); lcd.setCursor(0,0); lcd.print("Tacho Meter&Counter"); } void loop() { start_time=millis(); end_time=start_time+1000; while(millis()
- Web Server Based GPS Neo-6M
This tutorial, we will explore how to read GPS location data in simple local web server is created using NodeMCU and the location details are updated in that server webpage. In this Current location in Goolge Maps by clicking on the link provided in the Local web page. GPS stands for Global Positioning System and it is used to find out location, altitude, speed, date and time in UTC. GPS module takes some time to capture location details once it is powered on. NodeMCU starts webserver and waits for a client to get connected to the webserver. Once client is connected to the webserver, NodeMCU sends location details to connected client. The location details are displayed in a simple webpage designed using HTML. Circuit Diagram: Components Required: NodeMCU ESP12 GPS6MV2 module (Neo 6M, u-bloxAG) GPS Neo 6M This is a complete GPS module that is based on the Ublox NEO 6M GPS. This unit uses the latest technology from Ublox to give the best possible positioning information and includes a larger built-in 25 x 25mm active GPS antenna with a UART TTL socket. A battery is also included so that you can obtain a GPS lock faster. This is an updated GPS module that can be used with ardupilot mega v2. This GPS module gives the best possible position information, allowing for better performance with your Ardupilot or other Multirotor control platform. The Ublox GPS module has serial TTL output, it has four pins: TX, RX, VCC, and GND. You can download the u-centre software for configuring the GPS and changing the settings and much more. It is really good software (see link below). Features: 5Hz position update rate Operating temperature range: -40 TO 85°CUART TTL socket EEPROM to save configuration settings Rechargeable battery for Backup The cold start time of 38 s and Hot start time of 1 s Supply voltage: 3.3 V Configurable from 4800 Baud to 115200 Baud rates. (default 9600) SuperSense ® Indoor GPS: -162 dBm tracking sensitivity Support SBAS (WAAS, EGNOS, MSAS, GAGAN) Separated 18X18mm GPS antenna Getting Location Data from GPS: The Module will transmit data in multiple strings at 9600 Baud Rate. If we use an UART terminal with 9600 Baud rate, we will see the data received by GPS. GPS module sends the Real time tracking position data in NMEA format. NMEA format consist several sentences, in which four important sentences are given below. More detail about the NMEA sentence and its data format can be found here. $GPGGA: Global Positioning System Fix Data $GPGSV: GPS satellites in view $GPGSA: GPS DOP and active satellites $GPRMC: Recommended minimum specific GPS/Transit data This is the data received by GPS when connected on 9600 baud rate. Installing the ESP8266_Arduino_Library Tiny GPS++ library : Download In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code #include #include #include TinyGPSPlus gps; // The TinyGPS++ object //SoftwareSerial ss(4, 5); // WO LCD OK, GPS (TX,RX) to ESP8266 12E (D2,D1)The serial connection to the GPS device // BOTH SERIAL WORKING FINE SoftwareSerial ss(14, 12); //WITH LCD THIS OK GPS (TX,RX) to ESP8266 12E (D5,D6)The serial connection to the GPS device //Replace with your network credentials char ssid[] = "TP-Link_3200"; // yOUR ssid char password[]="9500112137"; //yOUE wifI PASSWORD float latitude , longitude; int year , month , date, hour , minute , second; String date_str , time_str , lat_str , lng_str; int pm; #include LiquidCrystal_I2C lcd(0x27,16,2); WiFiServer server(80); void setup() { Serial.begin(115200); ss.begin(9600); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); lcd.setCursor(0,0); lcd.print("WiFi connected"); server.begin(); Serial.println("Server started"); // Print the IP address Serial.println(WiFi.localIP()); lcd.setCursor(0,1); lcd.print(WiFi.localIP()); delay(5000); lcd.clear(); } void loop() { while (ss.available() > 0) if (gps.encode(ss.read())) { if (gps.location.isValid()) { latitude = gps.location.lat(); lat_str = String(latitude , 6); longitude = gps.location.lng(); lng_str = String(longitude , 6); } if (gps.date.isValid()) { date_str = ""; date = gps.date.day(); month = gps.date.month(); year = gps.date.year(); if (date < 10) date_str = '0'; date_str += String(date); date_str += " / "; if (month < 10) date_str += '0'; date_str += String(month); date_str += " / "; if (year < 10) date_str += '0'; date_str += String(year); } if (gps.time.isValid()) { time_str = ""; hour = gps.time.hour(); minute = gps.time.minute(); second = gps.time.second(); minute = (minute + 30); if (minute > 59) { minute = minute - 60; hour = hour + 1; } hour = (hour + 5) ; if (hour > 23) hour = hour - 24; if (hour >= 12) pm = 1; else pm = 0; hour = hour % 12; if (hour < 10) time_str = '0'; time_str += String(hour); time_str += " : "; if (minute < 10) time_str += '0'; time_str += String(minute); time_str += " : "; if (second < 10) time_str += '0'; time_str += String(second); if (pm == 1) time_str += " PM "; else time_str += " AM "; } } lcd.setCursor(0,0); lcd.print("Latitude:"); lcd.print(gps.location.lat()); lcd.setCursor(0,1); lcd.print("Longitude:"); lcd.print(longitude = gps.location.lng()); // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Prepare the response String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n
- Web Server Based Wireless Video Streaming using ESP32 Camera
Here to show you how to setup a video streaming web server through Wifi network with low cost budget. Components Required ESP32-CAM with OV2640 FTDI programmer Jumper wires ESP32 Camera The ESP32 CAM WiFi Module Bluetooth with OV2640 Camera Module 2MP For Face Recognization has a very competitive small-size camera module that can operate independently as a minimum system with a footprint of only 40 x 27 mm; a deep sleep current of up to 6mA and is widely used in various IoT applications. It is suitable for home smart devices, industrial wireless control, wireless monitoring, and other IoT applications. This module adopts a DIP package and can be directly inserted into the backplane to realize rapid production of products, providing customers with high-reliability connection mode, which is convenient for application in various IoT hardware terminals. ESP integrates WiFi, traditional Bluetooth, and BLE Beacon, with 2 high-performance 32-bit LX6 CPUs, 7-stage pipeline architecture. It has the main frequency adjustment range of 80MHz to 240MHz, on-chip sensor, Hall sensor, temperature sensor, etc. Flash LED off: 180mA @ 5V. Flash LED on to maximum brightness: 310mA @ 5V. Deep-sleep: 6mA @ 5V min. Modem-sleep: 20mA @ 5V min. Light-sleep: 6.7mA @ 5V min. Features Here is a list with the ESP32-CAM features: The smallest 802.11b/g/n Wi-Fi BT SoC module Low power 32-bit CPU,can also serve the application processor Up to 160MHz clock speed, summary computing power up to 600 DMIPS Built-in 520 KB SRAM, external 4MPSRAM Supports UART/SPI/I2C/PWM/ADC/DAC Support OV2640 and OV7670 cameras, built-in flash lamp Support image WiFI upload Support TF card Supports multiple sleep modes Embedded Lwip and FreeRTOS Supports STA/AP/STA+AP operation mode Support Smart Config/AirKiss technology Support for serial port local and remote firmware upgrades (FOTA) Specifications : Wireless Module: ESP32-S WiFi 802.11 b/g/n + Bluetooth 4.2 LE module with PCB antenna, u.FL connector, 32Mbit SPI flash, 4MBit PSRAM. External Storage: micro SD card slot up to 4GB. Camera FPC connector. Support for OV2640 (sold with a board) or OV7670 cameras. Image Format: JPEG( OV2640 support only ), BMP, grayscale. LED flashlight. Expansion: 16x through-holes with UART, SPI, I2C, PWM. Misc: Reset button. Power Supply: 5V via pin header. Power Consumption. Flash LED off: 180mA @ 5V. Flash LED on to maximum brightness: 310mA @ 5V. Deep-sleep: 6mA @ 5V min. Modem-sleep: 20mA @ 5V min. Light-sleep: 6.7mA @ 5V min. Dimensions (ESP32): 40 x 27 x 12 (LxWxH) mm. Temperature Range: Operating: -20 ℃ ~ 85 ℃; storage: -40 ℃ ~ 90 ℃ @ < 90%RH. ESP32-CAM Pinout The following figure shows the ESP32-CAM pinout (AI-Thinker module). There are three GND pins and two pins for power: either 3.3V or 5V. GPIO 1 and GPIO 3 are the serial pins. You need these pins to upload code to your board. Additionally, GPIO 0 also plays an important role, since it determines whether the ESP32 is in flashing mode or not. When GPIO 0 is connected to GND, the ESP32 is in flashing mode. The following pins are internally connected to the microSD card reader: GPIO 14: CLK GPIO 15: CMD GPIO 2: Data 0 GPIO 4: Data 1 (also connected to the on-board LED) GPIO 12: Data 2 GPIO 13: Data 3 Install the ESP32 add-on In this example, we use Arduino IDE to program the ESP32-CAM board. So, you need to have Arduino IDE installed as well as the ESP32 add-on Circuit Diagram: Connect the ESP32-CAM board to your computer using an FTDI programmer. Many FTDI programmers have a jumper that allows you to select 3.3V or 5V. Make sure the jumper is in the right place to select 5V. ESP32-CAM FTDI Programmer GND GND 5VVCC (5V) U0R TX U0T RX GPIO 0 GND To upload the code, follow the next steps: Go to Tools > Board and select AI-Thinker ESP32-CAM. Go to Tools > Port and select the COM port the ESP32 is connected to. Then, click the upload button to upload the code. When you start to see these dots on the debugging window as shown below, press the ESP32 CAM on-board RST button. After a few seconds, the code should be successfully uploaded to your board. Getting the IP address After uploading the code, disconnect GPIO 0 from GND. Open the Serial Monitor at a baud rate of 115200. Press the ESP32-CAM on-board Reset button. The ESP32 IP address should be printed in the Serial Monitor. Accessing the Video Streaming Server Now, you can access your camera streaming server on your local network. Open a browser and type the ESP32-CAM IP address. Press the Start Streaming button to start video streaming. There are also several camera settings that you can play with to adjust the image settings. Subscribe and Download code. Arduino Code: Download
- Pan Tilt Servo Control Using NodeMCU
This tutorial, we will explore how to control Pan & Tilt servos using ESP8266, myDevices Cayenne, and MQTT, Our goal will be a PAN/TILT mechanism to position a camera (ESP32 Camera). Pan and tilt systems used in today's robotics applications for security, industrial, and military applications have to move faster, smoother, and more accurately than ever before. At the same time, these systems need to be cost effective, easy to program. On the other hand, Cayenne is an IoT cloud platform that provides several cloud services, such as: Data visualization IoT cloud Alerts Scheduling Events We will focus our attention on data visualization and on the IoT cloud services. Refer my previous post for Servo control: https://www.dofbot.com/post/cayenne-iot-based-servo-control Circuit Diagram Components Required ESP8266 12E Servo Motor SG90 or MG90S Pan tilt Servo Bracket Servo Tetser Pan tilt Servo Bracket Assembly In this assembly some Cut to be done in the servo knob before assembly, see the demo video for detail. Pan tilt Servo Bracket Test After Assembly we need to check the servo using the servo tester. see the demo video for Servo testing detail. Demo Video for servo Assembly and Test Connecting the Servo Motor to the ESP8266 Servo motors have three wires: power, ground, and signal. Servo Wire Color Power-Red GND-Black, or brown Signal-Yellow, orange, or white When using a small servo like the SG90 as shown in the figure below, you can power it directly from the ESP8266. If you’re using a small servo like the SG90, you need to connect: GND -> ESP8266 GND pin; Power -> ESP8266 Vin pin; Signal -> D1 and D2 (or any PWM pin). Installing the ESP8266_Arduino_Library The ESP32 Arduino Servo Library makes it easier to control a servo motor with your ESP8266, using the Arduino IDE. Follow the next steps to install the library in your Arduino IDE: After Download the ESP32_Arduino_Servo_Library. You should have a .zip folder in your Downloads folder, Unzip the .zip folder and you should get ESP32-Arduino-Servo-Library. Download the Cayenne-MQTT-ESP-master library from this link. Click on Add ZIP Library and add Cayenne-MQTT-ESP-master zip file, or directly copy the folder (Cayenne-MQTT-ESP-master) and paste it in Libraries folder of Arduino IDE. After installing the library, go to your Arduino IDE. Make sure you have the Nodemcu 1.0 ESP-12E board selected, and then, Copy and Paste code in Arduino IDE. Subscribe and Download code. Subscribe and Download code. Arduino code #include #include #include char ssid[] = "TP-Link_3200"; char password[]="9500112137"; char username[] = "2031dd30-5414-11eb-b767-3f1a8f1211ba"; char mqtt_password[] = "f2ce829d98df3a768328ac6936eae9fd47d28289"; char client_id[] = "fbaaa920-6565-11eb-8779-7d56e82df461"; Servo myservo1; Servo myservo2; void setup() { myservo1.attach(D1); myservo2.attach(D2); Cayenne.begin(username,mqtt_password,client_id,ssid,password); } void loop() { Cayenne.loop(); } CAYENNE_IN(1) { int position = getValue.asDouble() * 180; myservo1.write(getValue.asInt()); } CAYENNE_IN(2) { int position = getValue.asDouble() * 180; myservo2.write(getValue.asInt()); } Hardware interfacing with Cayenne IoT platform refer detail: https://www.dofbot.com/post/cayenne-iot-based-weather-monitor Click on Add new and then Device/Widget in Settings, Add New Device here and select Slider for Controlling Servo 0 to 180 angle by step 1 angle to desired step value. Configure device Generic ESP8266, MQTT username, password and client ID from Create App Paste these respective details under username, password and client ID in Arduino source code , along with your Wi-Fi name and password. After successfully compiling and uploading the code to NodeMCU, You will see ESP8266 connected to Wi-Fi. After the connection is established, the previous page is automatically updated on Cayenne. A new dashboard opens in the browser. Cayenne generates an ID and a device icon for your device. Click on Custom Widgets and then value, and populate all fields .
- IoT Based Home automation
In This tutorial to build a standalone ESP8266 NodeMCU Web Server that controls any relay module. We’ll create an ESP8266 Web Server and it can be accessed with any device with a Web browser in your local network. Circuit Diagram Components Required ESP8266 12E 4 Channel Relay Module Jumper wires 4 Channel Isolated 5A or 10A Relay HW-316 The 4 Channel Relay Breakout is an easy way to use your Arduino, Raspberry Pi, or other microcontroller to switch high voltages and high current loads. ... Each relay has the common, normally open, and normally closed pin broken out to a convenient 5.0mm pitch screw terminal. While this board can be used to switch mains power, it should be done so using extreme caution. This should not be done without the aid of an experienced electrician. Equiped with high-current relay, AC250V 10A ; DC30V 10A 5V 4-Channel Relay interface board, and each one needs 50-60mA Driver Current Be able to control various appliances, and other equipments with large current Application:Supports all MCU control, The industrial field, PLC control, Smart home control Indication LED's for Relay output status Installing the ESP8266_Arduino_Library Click here to download the ESPAsyncWebServer library Click here to download the AsyncTCP library (ESP32) Click here to download the ESPAsyncTCP library (ESP8266 NodeMCU) Subscribe and Download code. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code #include "ESP8266WiFi.h" #include "ESPAsyncWebServer.h" // Set to true to define Relay as Normally Open (NO) #define RELAY_NO true // Set number of relays #define NUM_RELAYS 4 // Assign each GPIO to a relay int relayGPIOs[NUM_RELAYS] = {5, 4, 14, 12}; // WiFi login parameters - network name and password const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; // your WIFi Password const char* PARAM_INPUT_1 = "relay"; const char* PARAM_INPUT_2 = "state"; // Create AsyncWebServer object on port 80 AsyncWebServer server(80); const char index_html[] PROGMEM = R"rawliteral( ESP8266 Home Automation Web Sever %BUTTONPLACEHOLDER% )rawliteral"; // Replaces placeholder with button section in your web page String processor(const String& var){ //Serial.println(var); if(var == "BUTTONPLACEHOLDER"){ String buttons =""; for(int i=1; i<=NUM_RELAYS; i++){ String relayStateValue = relayState(i); buttons+= "Device : " + String(i) + ""; } return buttons; } return String(); } String relayState(int numRelay){ if(RELAY_NO){ if(digitalRead(relayGPIOs[numRelay-1])){ return ""; } else { return "checked"; } } else { if(digitalRead(relayGPIOs[numRelay-1])){ return "checked"; } else { return ""; } } return ""; } void setup(){ // Serial port for debugging purposes Serial.begin(115200); // Set all relays to off when the program starts - if set to Normally Open (NO), the relay is off when you set the relay to HIGH for(int i=1; i<=NUM_RELAYS; i++){ pinMode(relayGPIOs[i-1], OUTPUT); if(RELAY_NO){ digitalWrite(relayGPIOs[i-1], HIGH); } else{ digitalWrite(relayGPIOs[i-1], LOW); } } // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); } // Print ESP8266 Local IP Address Serial.println(WiFi.localIP()); // Route for root / web page server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); // Send a GET request to /update?relay=&state= server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) { String inputMessage; String inputParam; String inputMessage2; String inputParam2; // GET input1 value on /update?relay= if (request->hasParam(PARAM_INPUT_1) & request->hasParam(PARAM_INPUT_2)) { inputMessage = request->getParam(PARAM_INPUT_1)->value(); inputParam = PARAM_INPUT_1; inputMessage2 = request->getParam(PARAM_INPUT_2)->value(); inputParam2 = PARAM_INPUT_2; if(RELAY_NO){ Serial.print("NO "); digitalWrite(relayGPIOs[inputMessage.toInt()-1], !inputMessage2.toInt()); } else{ Serial.print("NC "); digitalWrite(relayGPIOs[inputMessage.toInt()-1], inputMessage2.toInt()); } } else { inputMessage = "No message sent"; inputParam = "none"; } Serial.println(inputMessage + inputMessage2); request->send(200, "text/plain", "OK"); }); // Start server server.begin(); } void loop() { } After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address.












