instruction
stringlengths 40
100
| input
stringlengths 136
25.5k
| output
stringlengths 207
10.3k
|
---|---|---|
Generate a diagram.json code for Digital Voltmeter | #include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define POT_PIN A0
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD I2C address
void setup() {
lcd.begin();
lcd.print("Voltmeter");
}
void loop() {
int sensorValue = analogRead(POT_PIN);
float voltage = sensorValue * (5.0 / 1023.0);
lcd.setCursor(0, 1);
lcd.print("Voltage: ");
lcd.print(voltage);
lcd.print(" V");
delay(500);
} | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 0.6, "left": -0.6, "attrs": {} },
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -116.5, "left": 86.2, "attrs": {} },
{
"type": "wokwi-lcd1602",
"id": "lcd1",
"top": 217.6,
"left": -13.6,
"attrs": { "pins": "i2c" }
}
],
"connections": [
[ "pot1:VCC", "uno:5V", "red", [ "v57.6", "h162.4", "v220.8", "h-124.8" ] ],
[ "pot1:GND", "uno:GND.1", "black", [ "v0" ] ],
[ "pot1:SIG", "uno:A0", "orange", [ "v163.2", "h76.4" ] ],
[ "lcd1:GND", "uno:GND.2", "black", [ "h-9.6", "v-38.4", "h192" ] ],
[ "lcd1:VCC", "uno:5V", "red", [ "h-28.8", "v-38.3", "h201.6" ] ],
[ "lcd1:SDA", "uno:A4", "magenta", [ "h-38.4", "v57.8", "h355.2" ] ],
[ "lcd1:SCL", "uno:A5", "white", [ "h-28.8", "v86.7", "h364.8", "v-163.2" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Analog joy stick control using arduino-mega | #include <Adafruit_NeoPixel.h>
#define PIN 6 // Pin connected to the Data In of the NeoPixel ring
#define NUMPIXELS 16 // Number of LEDs in the ring
#define JOYSTICK_X A0 // Analog pin connected to the joystick's VRx
#define JOYSTICK_Y A1 // Analog pin connected to the joystick's VRy
#define JOYSTICK_SW 2 // Digital pin connected to the joystick's switch
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // Initialize the NeoPixel library
pinMode(JOYSTICK_SW, INPUT_PULLUP); // Set the switch pin as input with pull-up resistor
Serial.begin(9600);
}
void loop() {
int xValue = analogRead(JOYSTICK_X); // Read the horizontal value
int yValue = analogRead(JOYSTICK_Y); // Read the vertical value
int swValue = digitalRead(JOYSTICK_SW); // Read the switch value
// Map the joystick values to the number of LEDs
int xMapped = map(xValue, 0, 1023, 0, NUMPIXELS);
int yMapped = map(yValue, 0, 1023, 0, NUMPIXELS);
// Set the color of the LEDs based on the joystick position
for (int i = 0; i < NUMPIXELS; i++) {
if (i == xMapped || i == yMapped) {
pixels.setPixelColor(i, pixels.Color(255, 0, 0)); // Set the color to red
} else {
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Turn off the other LEDs
}
}
pixels.show(); // Update the LEDs
Serial.print("X: ");
Serial.print(xValue);
Serial.print(" Y: ");
Serial.print(yValue);
Serial.print(" SW: ");
Serial.println(swValue);
delay(100); // Short delay to avoid rapid changes
} | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-mega", "id": "mega", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-analog-joystick",
"id": "joystick1",
"top": -173.4,
"left": 168.6,
"attrs": {}
},
{
"type": "wokwi-led-ring",
"id": "ring1",
"top": -162.56,
"left": -162.01,
"attrs": { "pixels": "16" }
}
],
"connections": [
[ "joystick1:VCC", "mega:5V", "red", [ "v48", "h-37.1" ] ],
[ "joystick1:GND", "mega:GND.2", "black", [ "v115.2", "h-57.6", "v134.4" ] ],
[ "joystick1:HORZ", "mega:A0", "white", [ "v0" ] ],
[ "joystick1:VERT", "mega:A1", "cyan", [ "v0" ] ],
[ "joystick1:SEL", "mega:2", "green", [ "v0" ] ],
[ "ring1:GND", "mega:GND.3", "black", [ "v220.8", "h288" ] ],
[ "ring1:VCC", "mega:5V", "red", [ "v211.2", "h259.2" ] ],
[ "ring1:DIN", "mega:6", "green", [ "v-9.6", "h288" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Digital thermometer using DHT-22 and arduino-uno | #include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD I2C address
void setup() {
lcd.begin();
dht.begin();
lcd.print("Temp:");
}
void loop() {
float temp = dht.readTemperature();
lcd.setCursor(6, 0);
lcd.print(temp);
lcd.print(" C");
delay(2000);
} | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 77.4, "left": -106.2, "attrs": {} },
{ "type": "wokwi-dht22", "id": "dht1", "top": -114.9, "left": -24.6, "attrs": {} },
{
"type": "wokwi-lcd1602",
"id": "lcd1",
"top": -108.8,
"left": 82.4,
"attrs": { "pins": "i2c" }
}
],
"connections": [
[ "dht1:VCC", "uno:5V", "red", [ "v297.6", "h57.6" ] ],
[ "dht1:GND", "uno:GND.2", "black", [ "v307.2", "h48" ] ],
[ "dht1:SDA", "uno:2", "green", [ "v67.2", "h124.9" ] ],
[ "lcd1:GND", "uno:GND.3", "black", [ "h0" ] ],
[ "lcd1:VCC", "uno:5V", "red", [ "h0" ] ],
[ "lcd1:SDA", "uno:A4", "green", [ "h0" ] ],
[ "lcd1:SCL", "uno:A5", "green", [ "h0" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for LED Chaser using Arduino-mega | const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
const int numLeds = sizeof(ledPins) / sizeof(ledPins[0]);
void setup() {
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100); // Adjust delay to change the speed of the chaser
digitalWrite(ledPins[i], LOW);
}
} | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-breadboard-mini", "id": "bb1", "top": -135.8, "left": 352.8, "attrs": {} },
{ "type": "wokwi-arduino-mega", "id": "mega", "top": 0, "left": 0, "attrs": {} },
{ "type": "wokwi-led", "id": "led1", "top": -109.2, "left": 71, "attrs": { "color": "red" } },
{
"type": "wokwi-led",
"id": "led2",
"top": -109.2,
"left": 109.4,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -109.2,
"left": 147.8,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led4",
"top": -109.2,
"left": 186.2,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led5",
"top": -109.2,
"left": 224.6,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led6",
"top": -109.2,
"left": 253.4,
"attrs": { "color": "red" }
}
],
"connections": [
[ "led6:A", "mega:2", "green", [ "v0" ] ],
[ "led4:A", "mega:4", "green", [ "v57.6", "h9.6" ] ],
[ "led3:A", "mega:5", "green", [ "v57.6", "h28.8" ] ],
[ "led2:A", "mega:6", "green", [ "v67.2", "h67.2" ] ],
[ "led1:A", "mega:7", "green", [ "v96", "h96" ] ],
[ "led5:A", "mega:3", "green", [ "v57.6", "h-19.2" ] ],
[ "mega:GND.2", "bb1:8b.j", "black", [ "v26.7", "h267.35" ] ],
[ "led5:C", "bb1:8b.g", "green", [ "v0" ] ],
[ "led4:C", "bb1:8b.h", "green", [ "v0" ] ],
[ "led3:C", "bb1:8b.i", "green", [ "v0" ] ],
[ "bb1:8b.f", "bb1:8t.e", "green", [ "v0" ] ],
[ "led1:C", "bb1:8t.c", "green", [ "v9.6", "h-18.8", "v-48" ] ],
[ "led2:C", "bb1:8t.b", "green", [ "v19.2", "h-18.8", "v-76.8" ] ],
[ "led6:C", "bb1:8t.a", "green", [ "v9.6", "h-9.2", "v-67.2" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for smart buzzer system using esp-32 | #include <IRremote.h>
const int irPin = 14; // GPIO pin connected to the IR receiver
const int buzzerPin = 13; // GPIO pin connected to the buzzer
IRrecv irrecv(irPin);
decode_results results;
void setup() {
irrecv.enableIRIn(); // Start the receiver
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
Serial.begin(115200);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX); // Print the received IR code in hexadecimal
switch (results.value) {
case 0xFFA25D: // Example IR code for a specific button
tone(buzzerPin, 1000, 500); // Play a tone at 1000Hz for 500ms
break;
case 0xFF629D: // Another example IR code
tone(buzzerPin, 2000, 500); // Play a tone at 2000Hz for 500ms
break;
// Add more cases for different buttons if needed
default:
noTone(buzzerPin); // Turn off the buzzer for unrecognized codes
break;
}
irrecv.resume(); // Receive the next value
}
}
/*IR Receiver Module:
VCC to 3.3V on the ESP32
GND to GND on the ESP32
DAT to 14 on the ESP32
Buzzer:
bz1:2 to 13 on the ESP32
bz1:1 to GND on the ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} },
{ "type": "wokwi-ir-receiver", "id": "ir1", "top": -97.35, "left": -78.58, "attrs": {} },
{
"type": "wokwi-buzzer",
"id": "bz1",
"top": -84,
"left": 97.8,
"attrs": { "volume": "0.1" }
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "ir1:VCC", "esp:3V3", "red", [ "v0" ] ],
[ "ir1:GND", "esp:GND.1", "black", [ "v0" ] ],
[ "ir1:DATA", "esp:14", "green", [ "v0" ] ],
[ "bz1:1", "esp:GND.2", "green", [ "v0" ] ],
[ "bz:2", "esp:13", "green", [ "v0" ] ],
[ "bz1:2", "esp:13", "green", [ "v0" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Smart street light using LDR and arduino-uno | const int ldrPin = A0; // Analog pin connected to the LDR
const int ledPin = 9; // Digital pin connected to the LED
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the value from the LDR
Serial.println(ldrValue); // Print the LDR value to the Serial Monitor
// Adjust the threshold value according to your needs
if (ldrValue < 500) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(100); // Short delay to avoid rapid changes
}
/*Hardware Connections:
Photoresistor Sensor (LDR):
VCC of the LDR to 5V on the Arduino Uno
AO of the LDR to A0 on the Arduino Uno
GND of LDR to GND on th Arduino-Uno
LED:
A of the LED to a 220Ω resistor, then to D9 on the Arduino Uno
C of the LED to GND on the Arduino Uno*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-photoresistor-sensor",
"id": "ldr1",
"top": -92.8,
"left": 48.8,
"attrs": {}
},
{ "type": "wokwi-led", "id": "led1", "top": -51.6, "left": 23, "attrs": { "color": "green" } },
{
"type": "wokwi-resistor",
"id": "r1",
"top": 72,
"left": 47.45,
"rotate": 90,
"attrs": { "value": "220" }
}
],
"connections": [
[ "ldr1:VCC", "uno:5V", "red", [ "h67.2", "v288", "h-124.8" ] ],
[ "ldr1:AO", "uno:A0", "green", [ "h57.6", "v248.9", "h-67.2" ] ],
[ "ldr1:GND", "uno:GND.2", "black", [ "h0" ] ],
[ "led1:A", "r1:1", "green", [ "v0" ] ],
[ "r1:2", "uno:9", "green", [ "h0" ] ],
[ "led1:C", "uno:GND.3", "black", [ "v0" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Touchless door bell using IR flame sensor,arduino-uno,buzzer | // Pin Definitions
const int irSensorPin = 2; // Digital pin connected to the IR sensor output
const int buzzerPin = 3; // Digital pin connected to the buzzer
void setup() {
// Initialize the IR sensor pin as an input
pinMode(irSensorPin, INPUT);
// Initialize the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
// Start the serial communication for debugging purposes
Serial.begin(9600);
}
void loop() {
// Read the state of the IR sensor
int sensorValue = digitalRead(irSensorPin);
// If the sensor detects an object (output is HIGH)
if (sensorValue == HIGH) {
// Turn on the buzzer
digitalWrite(buzzerPin, HIGH);
Serial.println("Visitor detected! Buzzer ON.");
} else {
// Turn off the buzzer
digitalWrite(buzzerPin, LOW);
Serial.println("No visitor. Buzzer OFF.");
}
// Short delay to avoid rapid changes
delay(100);
}
/*IR Sensor Module:
VCC to 5V on the Arduino Uno
GND to GND on the Arduino Uno
DOUT to D2 on the Arduino Uno
Buzzer:
bz1:2 to D3 on the Arduino Uno
bz1:1 to GND on the Arduino Uno*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 29.4, "left": -0.6, "attrs": {} },
{
"type": "wokwi-flame-sensor",
"id": "led1",
"top": -81.8,
"left": -16.6,
"attrs": { "color": "red" }
},
{
"type": "wokwi-buzzer",
"id": "bz1",
"top": -84,
"left": 241.8,
"attrs": { "volume": "0.1" }
}
],
"connections": [
[ "led1:VCC", "uno:5V", "red", [ "h28.8", "v259.2", "h-48" ] ],
[ "led1:GND", "uno:GND.1", "black", [ "h9.6", "v76.7", "h-76.8" ] ],
[ "bz1:1", "uno:GND.2", "black", [ "v0" ] ],
[ "bz1:2", "uno:3", "red", [ "v0" ] ],
[ "led1:DOUT", "uno:2", "violet", [ "h0" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Gas Leakage Detector – Gas Sensor + Buzzer + ESP32 Devkit V1 | // Define the pin connections
const int gasSensorPin = A0; // Analog pin connected to the gas sensor's AO
const int buzzerPin = 13; // Digital pin connected to the buzzer
void setup() {
// Initialize the gas sensor pin as an input
pinMode(gasSensorPin, INPUT);
// Initialize the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
// Start the serial communication for debugging purposes
Serial.begin(115200);
}
void loop() {
// Read the analog value from the gas sensor
int sensorValue = analogRead(gasSensorPin);
// Print the sensor value to the Serial Monitor for debugging
Serial.println(sensorValue);
// Adjust the threshold value according to your needs
// If the sensor value exceeds the threshold (indicating gas leakage)
if (sensorValue > 300) {
// Turn on the buzzer
digitalWrite(buzzerPin, HIGH);
Serial.println("Gas detected! Buzzer ON.");
} else {
// Turn off the buzzer
digitalWrite(buzzerPin, LOW);
Serial.println("No gas detected. Buzzer OFF.");
}
// Short delay to avoid rapid changes
delay(100);
}
/*Gas Sensor (MQ-2):
VCC to 3.3V on the ESP32
GND to GND on the ESP32
AO to A0 on the ESP32 (Analog output)
Buzzer:
bz1:2 to D13 on the ESP32
bz1:1 to GND on the ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 38.4, "left": 14.44, "attrs": {} },
{
"type": "wokwi-gas-sensor",
"id": " ",
"top": -74.1,
"left": -31.4,
"attrs": { "color": "red" }
},
{
"type": "wokwi-buzzer",
"id": "bz1",
"top": -55.2,
"left": 165,
"attrs": { "volume": "0.1" }
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ " :VCC", "esp:5V", "red", [ "h19.2", "v56.7", "h-134.4", "v192" ] ],
[ " :GND", "esp:GND.2", "black", [ "h38.4", "v104.8" ] ],
[ " :AOUT", "esp:0", "green", [ "h28.8", "v249.6" ] ],
[ "bz1:1", "esp:GND.1", "green", [ "v172.8", "h-163.2", "v-9.6" ] ],
[ "bz1:2", "esp:13", "green", [ "v182.4", "h-202" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Gesture-Controlled LED Strip – MPU6050 + NeoPixel + Arduino Nano | #include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <MPU6050.h>
// Pin definitions
#define NEOPIXEL_PIN 6 // Data pin for NeoPixel
#define NUMPIXELS 16 // Number of LEDs in the NeoPixel strip
// Initialize the NeoPixel object
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Initialize the MPU6050 object
MPU6050 mpu;
void setup() {
// Start the serial communication for debugging purposes
Serial.begin(9600);
// Initialize the NeoPixel strip
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// Initialize the MPU6050 sensor
Wire.begin();
mpu.initialize();
// Check if the MPU6050 is connected
if (mpu.testConnection()) {
Serial.println("MPU6050 connected successfully!");
} else {
Serial.println("MPU6050 connection failed!");
}
}
void loop() {
// Variables to hold accelerometer data
int16_t ax, ay, az;
// Read the accelerometer data
mpu.getAcceleration(&ax, &ay, &az);
// Print the accelerometer data for debugging purposes
Serial.print("aX = "); Serial.print(ax);
Serial.print(" | aY = "); Serial.print(ay);
Serial.print(" | aZ = "); Serial.println(az);
// Map the accelerometer data to LED index
int ledIndex = map(ax, -17000, 17000, 0, NUMPIXELS - 1);
// Ensure the mapped value is within the LED strip range
ledIndex = constrain(ledIndex, 0, NUMPIXELS - 1);
// Clear all LEDs
strip.clear();
// Set the color of the LED based on the gesture
strip.setPixelColor(ledIndex, strip.Color(255, 0, 0)); // Red color for demonstration
// Show the updated colors on the LED strip
strip.show();
// Small delay to avoid rapid changes
delay(100);
}
/*Hardware Connections:
MPU6050 Module:
VCC to 5V on the Arduino Nano
GND to GND on the Arduino Nano
SDA to A4 on the Arduino Nano
SCL to A5 on the Arduino Nano
NeoPixel LED Strip:
VCC to 5V on the Arduino Nano
GND to GND on the Arduino Nano
DIN to D6 on the Arduino Nano*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
{ "type": "wokwi-mpu6050", "id": "imu1", "top": -101.78, "left": 31.12, "attrs": {} },
{
"type": "wokwi-led-ring",
"id": "ring1",
"top": 29.44,
"left": -85.21,
"attrs": { "pixels": "16" }
}
],
"connections": [
[ "imu1:VCC", "nano:5V", "red", [ "v-19.2", "h19.28" ] ],
[ "imu1:GND", "nano:GND.1", "black", [ "v-38.4", "h48.08" ] ],
[ "imu1:SCL", "nano:A5", "yellow", [ "v0" ] ],
[ "imu1:SDA", "nano:A4", "white", [ "h-9.52", "v158.4" ] ],
[ "ring1:DIN", "nano:6", "green", [ "v9.6", "h38.4" ] ],
[ "ring1:VCC", "nano:5V", "cyan", [ "v19.2", "h153.6" ] ],
[ "ring1:GND", "nano:GND.1", "#8f4814", [ "v28.8", "h211.2" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Obstacle Avoidance Robot – HCSR04 + Stepper Motor + ESP32 Devkit V1 | // Include necessary libraries
#include <Wire.h>
// Define pin connections
const int trigPin = 12; // GPIO pin connected to the HC-SR04 Trig pin
const int echoPin = 14; // GPIO pin connected to the HC-SR04 Echo pin
const int stepPin = 26; // GPIO pin connected to the A4988 STEP pin
const int dirPin = 25; // GPIO pin connected to the A4988 DIR pin
// Variables for distance calculation
long duration;
int distance;
void setup() {
// Set up the pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Initialize serial communication for debugging
Serial.begin(115200);
// Set initial motor direction
digitalWrite(dirPin, HIGH); // Set motor direction clockwise
}
void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin and calculate the duration
duration = pulseIn(echoPin, HIGH);
// Calculate the distance
distance = duration * 0.034 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// If an obstacle is detected within 20 cm, move the stepper motor backward
if (distance < 20) {
Serial.println("Obstacle detected! Moving backward.");
digitalWrite(dirPin, LOW); // Set motor direction counterclockwise
// Move the motor a few steps backward
for (int i = 0; i < 200; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500); // Adjust delay for motor speed
digitalWrite(stepPin, LOW);
delayMicroseconds(500); // Adjust delay for motor speed
}
} else {
// If no obstacle, move the stepper motor forward
Serial.println("No obstacle. Moving forward.");
digitalWrite(dirPin, HIGH); // Set motor direction clockwise
// Move the motor a few steps forward
for (int i = 0; i < 200; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500); // Adjust delay for motor speed
digitalWrite(stepPin, LOW);
delayMicroseconds(500); // Adjust delay for motor speed
}
}
// Small delay to avoid rapid changes
delay(500);
}
/*Hardware Connections:
HC-SR04 Ultrasonic Sensor:
VCC to 5V on the ESP32
GND to GND on the ESP32
Trig to GPIO 12 on the ESP32
Echo to GPIO 14 on the ESP32
A4988 Motor Driver:
VMOT to 12V (external power supply)
GND to GND (external power supply)
2B to Step Motor Coil B-
2A to Step Motor Coil B+
1A to Step Motor Coil A+
1B to Step Motor Coil A-
VDD to 3.3V on ESP32
GND to GND on ESP32
STEP to GPIO 26 on ESP32
DIR to GPIO 25 on ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 28.8, "left": 14.44, "attrs": {} },
{ "type": "wokwi-hc-sr04", "id": "ultrasonic1", "top": -104.1, "left": -52.1, "attrs": {} },
{
"type": "wokwi-stepper-motor",
"id": "stepper1",
"top": -15.59,
"left": -201.17,
"attrs": { "size": "17" }
},
{ "type": "wokwi-a4988", "id": "drv1", "top": 225.6, "left": -129.6, "attrs": {} },
{ "type": "wokwi-vcc", "id": "vcc1", "top": 259.96, "left": -19.2, "attrs": {} },
{ "type": "wokwi-gnd", "id": "gnd1", "top": 316.8, "left": -19.8, "attrs": {} }
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "ultrasonic1:VCC", "esp:5V", "red", [ "v28.8", "h-48", "v211.2", "h48" ] ],
[ "ultrasonic1:GND", "esp:GND.2", "black", [ "v28.8", "h85.2", "v38.4" ] ],
[ "ultrasonic1:TRIG", "esp:12", "green", [ "v48", "h-29.2", "v134.4" ] ],
[ "ultrasonic1:ECHO", "esp:14", "green", [ "v57.6", "h-29.6", "v115.2" ] ],
[ "drv1:VMOT", "vcc1:VCC", "green", [ "h38.55", "v86.48" ] ],
[ "drv1:GND.2", "gnd1:GND", "black", [ "h28.95", "v86.48" ] ],
[ "drv1:2B", "stepper1:B-", "green", [ "h19.35", "v-67.12", "h-48" ] ],
[ "stepper1:B+", "drv1:2A", "magenta", [ "v0" ] ],
[ "stepper1:A+", "drv1:1A", "gold", [ "v0" ] ],
[ "stepper1:A-", "drv1:1B", "gray", [ "v0" ] ],
[ "drv1:VDD", "esp:3V3", "blue", [ "h28.95", "v-230.32" ] ],
[ "drv1:GND.1", "esp:GND.1", "black", [ "v0.08", "h57.75", "v-96" ] ],
[ "drv1:STEP", "esp:26", "#8f4814", [ "h-19.2", "v86.4", "h172.8", "v-230.4" ] ],
[ "drv1:DIR", "esp:25", "cyan", [ "h-9.6", "v67.2", "h172.8", "v-230.4" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for WiFi Weather Dashboard – ESP32 Devkit V1 + DHT22 + SSD1306 | #include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#include <WiFi.h>
// OLED display dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Declaration for SSD1306 display connected using I2C (SDA, SCL)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// DHT22 sensor
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Wi-Fi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
void setup() {
Serial.begin(115200);
// Initialize the DHT sensor
dht.begin();
// Initialize OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
display.print("Connecting to WiFi");
display.display();
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
display.clearDisplay();
display.print("WiFi connected");
display.display();
delay(1000);
display.clearDisplay();
}
void loop() {
// Read humidity and temperature values
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed and exit early
if (isnan(humidity) || isnan(temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Display the data on the OLED screen
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Temperature: ");
display.print(temperature);
display.print(" *C");
display.setCursor(0, 10);
display.print("Humidity: ");
display.print(humidity);
display.print(" %");
display.display();
delay(2000); // Update every 2 seconds
}
/*DHT22 Sensor:
VCC to 3.3V on the ESP32
GND to GND on the ESP32
SDA to GPIO 4 on the ESP32 (with a 10kΩ pull-up resistor to 3.3V)
SSD1306 OLED Display:
VCC to 3.3V on the ESP32
GND to GND on the ESP32
SDA to GPIO 21 on the ESP32
SCL to GPIO 22 on the ESP32 | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} },
{ "type": "wokwi-dht22", "id": "dht1", "top": -114.9, "left": -82.2, "attrs": {} },
{
"type": "board-ssd1306",
"id": "oled1",
"top": -64.06,
"left": 134.63,
"attrs": { "i2cAddress": "0x3c" }
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "dht1:VCC", "esp:3V3", "red", [ "v0" ] ],
[ "dht1:SDA", "esp:4", "green", [ "v0" ] ],
[ "dht1:GND", "esp:GND.1", "black", [ "v0" ] ],
[ "oled1:VCC", "esp:3V3", "#8f4814", [ "v-19.2", "h-182.25" ] ],
[ "oled1:GND", "esp:GND.2", "black", [ "v-9.6", "h-57.6", "v105.6" ] ],
[ "oled1:SCL", "esp:22", "white", [ "v-48", "h57.9", "v172.8" ] ],
[ "oled1:SDA", "esp:21", "blue", [ "v-28.8", "h57.67", "v172.8" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for IoT Home Security System– PIR Motion Sensor + Buzzer + ESP32 | // Define the pin connections
const int pirPin = 13; // GPIO pin connected to the PIR sensor output
const int buzzerPin = 12; // GPIO pin connected to the buzzer
void setup() {
// Set up the PIR sensor pin as an input
pinMode(pirPin, INPUT);
// Set up the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
// Start the serial communication for debugging purposes
Serial.begin(115200);
// Connect to WiFi network
WiFi.begin("your_SSID", "your_PASSWORD");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
}
void loop() {
// Read the state of the PIR sensor
int sensorValue = digitalRead(pirPin);
// If the sensor detects motion (output is HIGH)
if (sensorValue == HIGH) {
// Turn on the buzzer
digitalWrite(buzzerPin, HIGH);
Serial.println("Motion detected! Buzzer ON.");
// Send alert to a server (example URL)
WiFiClient client;
if (client.connect("example.com", 80)) {
client.print("GET /alert?motion=detected HTTP/1.1\r\n");
client.print("Host: example.com\r\n");
client.print("Connection: close\r\n\r\n");
client.stop();
}
} else {
// Turn off the buzzer
digitalWrite(buzzerPin, LOW);
Serial.println("No motion detected. Buzzer OFF.");
}
// Small delay to avoid rapid changes
delay(1000);
}
/*Hardware Connections:
PIR Motion Sensor:
VCC to 5V on the ESP32
GND to GND on the ESP32
OUT to GPIO 13 on the ESP32
Buzzer:
bz1:2 to GPIO 12 on the ESP32
bz1:1 to GND on the ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 249.6, "left": 216.04, "attrs": {} },
{ "type": "wokwi-pir-motion-sensor", "id": "pir1", "top": 138.4, "left": 50.22, "attrs": {} },
{
"type": "wokwi-buzzer",
"id": "bz1",
"top": 175.2,
"left": 357,
"attrs": { "volume": "0.1" }
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "pir1:VCC", "esp:5V", "red", [ "v220.8", "h134.4" ] ],
[ "pir1:OUT", "esp:13", "green", [ "v0" ] ],
[ "pir1:GND", "esp:GND.1", "black", [ "v0" ] ],
[ "bz1:1", "esp:GND.3", "black", [ "v0" ] ],
[ "bz1:2", "esp:12", "green", [ "v0" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for IoT-Based Step Counter – MPU6050 + OLED SSD1306 + ESP32 Devkit V1 | #include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <MPU6050.h>
// OLED display dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Declaration for SSD1306 display connected using I2C (SDA, SCL)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// MPU6050 sensor
MPU6050 mpu;
int stepCounter = 0;
bool isStep = false;
void setup() {
// Start the serial communication
Serial.begin(115200);
// Initialize the MPU6050 sensor
Wire.begin();
mpu.initialize();
// Check if the MPU6050 is connected
if (mpu.testConnection()) {
Serial.println("MPU6050 connected successfully!");
} else {
Serial.println("MPU6050 connection failed!");
}
// Initialize the OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
// Variables to hold accelerometer data
int16_t ax, ay, az;
// Read the accelerometer data
mpu.getAcceleration(&ax, &ay, &az);
// Simple step detection logic (you may need to adjust thresholds)
if (abs(ax) > 15000 && !isStep) {
stepCounter++;
isStep = true;
} else if (abs(ax) < 15000) {
isStep = false;
}
// Display step count on the OLED
display.clearDisplay();
display.setCursor(0, 0);
display.print("Step Count: ");
display.print(stepCounter);
display.display();
// Small delay to avoid rapid changes
delay(100);
}
/*Hardware Connections:
MPU6050:
VCC to 3.3V on the ESP32
GND to GND on the ESP32
SDA to GPIO 21 on the ESP32
SCL to GPIO 22 on the ESP32
OLED SSD1306 Display:
VCC to 3.3V on the ESP32
GND to GND on the ESP32
SDA to GPIO 21 on the ESP32
SCL to GPIO 22 on the ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 4.84, "attrs": {} },
{ "type": "wokwi-mpu6050", "id": "imu1", "top": -34.58, "left": -84.08, "attrs": {} },
{
"type": "board-ssd1306",
"id": "oled1",
"top": -6.46,
"left": 125.03,
"attrs": { "i2cAddress": "0x3c" }
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "imu1:VCC", "esp:3V3", "red", [ "v-19.2", "h9.68" ] ],
[ "imu1:GND", "esp:GND.1", "black", [ "v0" ] ],
[ "imu1:SCL", "esp:22", "green", [ "v0" ] ],
[ "imu1:SDA", "esp:21", "green", [ "v0" ] ],
[ "oled1:GND", "esp:GND.2", "black", [ "v-38.4", "h-57.6" ] ],
[ "oled1:VCC", "esp:3V3", "red", [ "v-9.6", "h-163.05" ] ],
[ "oled1:SCL", "esp:22", "white", [ "v-19.2", "h-66.9", "v96" ] ],
[ "oled1:SDA", "esp:21", "purple", [ "v-28.8", "h-67.13", "v67.2" ] ]
],
"dependencies": {}
} |
Generate a diagram.json code for Soil moisture measurement using esp32 | // Define pin connections
const int soilMoisturePin = 36; // GPIO pin connected to the Soil Moisture Sensor's AO
void setup() {
// Start serial communication for debugging purposes
Serial.begin(115200);
// Initialize the soil moisture sensor pin as an input
pinMode(soilMoisturePin, INPUT);
}
void loop() {
// Read the value from the soil moisture sensor
int sensorValue = analogRead(soilMoisturePin);
// Print the sensor value to the Serial Monitor
Serial.print("Soil Moisture Value: ");
Serial.println(sensorValue);
// Small delay to avoid rapid changes
delay(1000);
}
/*Hardware Connections:
Soil Moisture Sensor:
VCC to 3V3 on the ESP32
GND to GND on the ESP32
AO (Analog Output) to A0 (GPIO 36) on the ESP32*/ | {
"version": 1,
"author": "Vigneshwaran",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} },
{
"type": "chip-soil-moisture-sensor",
"id": "chip1",
"top": -66.18,
"left": -62.4,
"attrs": {}
}
],
"connections": [
[ "esp:TX", "$serialMonitor:RX", "", [] ],
[ "esp:RX", "$serialMonitor:TX", "", [] ],
[ "chip1:VCC", "esp:5V", "red", [ "h-9.6", "v249.6" ] ],
[ "chip1:GND", "esp:GND.1", "black", [ "h0", "v201.6" ] ],
[ "chip1:AO", "esp:0", "green", [ "v28.8", "h69.01", "v172.8" ] ]
],
"dependencies": {}
}
{
"name": "soil-moisture-sensor",
"author": "Vigneshwaran",
"pins": [
"VCC",
"GND",
"AO"
],
"controls": []
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.