0% found this document useful (0 votes)
4 views12 pages

Arduino and Esp32 Part1

The document provides a detailed overview of Arduino and ESP32 components, including their functions and wiring. It also includes installation instructions for TensorFlow and OpenCV, basic programming codes for digital I/O, sensor readings, WiFi connection, and HTTP GET requests. Additionally, it features examples of using MQ sensors with Arduino and ESP32 for monitoring and data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Arduino and Esp32 Part1

The document provides a detailed overview of Arduino and ESP32 components, including their functions and wiring. It also includes installation instructions for TensorFlow and OpenCV, basic programming codes for digital I/O, sensor readings, WiFi connection, and HTTP GET requests. Additionally, it features examples of using MQ sensors with Arduino and ESP32 for monitoring and data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Arduino

Created by kishan yadav


Innovation group
Dissecting Arduino

USB
• Used to connect the Arduino to your computer.
• Transfers data (code uploads) and provides 5V power.
Polyfuse
• A resettable fuse that protects the board from drawing too much current from the
USB port.
• If too much current is drawn, it temporarily cuts off power until the issue is resolved.

5V Regulator
• Converts higher voltage (like 7-12V from the barrel jack) down to 5V.
• Powers the 5V components on the board safely.
Barrel Connector
• An input for external power (usually 7–12V DC) via an adapter.
• Ideal for projects needing higher power than USB can supply.
Output Capacitors
• Smooth out voltage fluctuations from the regulator.
• Ensure stable 5V and 3.3V outputs.
Reverse Voltage Protection Diode
• Prevents damage if the power is connected in reverse polarity.
• Ensures the current flows only in the correct direction.
Reverse Voltage Protection Diode
• Prevents damage if the power is connected in reverse polarity.
• Ensures the current flows only in the correct direction.
Input Capacitor
• Stabilizes input voltage from the barrel connector or Vin.
• Prevents voltage spikes.
3.3V Regulator
• Specifically steps down voltage to 3.3V.
• Powers low-voltage sensors or modules (like WiFi).
Power LED
• Glows when Arduino is powered (via USB or external source).
• Confirms the board is on.
LED Resistor
• Limits current to the built-in 'L' LED connected to pin 13.
• Protects the LED from burning out.
Microcontroller (ATmega328P)
• The brain of the Arduino.
• Runs your uploaded sketches (programs).

ESP32

ESP32-C6-WROOM-1 Module
• The main brain of the board.
• Contains a RISC-V core with:
o Wi-Fi 6 (802.11ax)
o Bluetooth 5.2
o Thread & Zigbee
• All your code runs on this chip.
Pin Headers
• General-purpose IO pins (GPIOs) accessible via headers on both sides.
• Used to connect sensors, motors, displays, etc.
• Can be used for PWM, ADC, I2C, SPI, UART, etc.
5V to 3.3V LDO (Low Dropout Regulator)
• Converts 5V input (from USB or external source) to 3.3V, which the ESP32 uses.
3.3V Power On LED
• Shows that the board is powered and the regulator is working properly.
USB-to-UART Bridge
• Converts USB signals to UART (serial) so you can upload code from your PC.
• Lets you use the Serial Monitor for debugging.
ESP32-C6 USB Type-C Port
• Direct USB connection to the ESP32 (native USB functionality).
• Can also be used to upload code or for USB device emulation (HID, Mass Storage,
etc.).
USB Type-C to UART Port
• Connects to the USB-to-UART bridge.
• Used for programming and debugging via serial.
Boot Button
• Press this while resetting to enter bootloader mode.
• Useful if your IDE (like Arduino or PlatformIO) can’t auto-detect the board.
Reset Button
• Resets the ESP32-C6 module.
• Used to reboot or restart the program.
RGB LED
• A built-in multi-color LED you can control via code.
• Useful for debugging, visual feedback, or effects.
J5
• Usually a jumper or header pad for debugging, testing, or expansion.
• May be connected to certain test signals or power rails.

Installing Tensorflow and Opencv


CPU-only installation:
python -m pip install --upgrade pip
pip install tensorflow
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000,1000])))"
Install OpenCV (Python)
pip install opencv-python
pip install opencv-python-headless
pip install opencv-contrib-python

import cv2
print(cv2.__version__)

Resistor Value Chart


5v regulator ic

MQ sensors

Wiring of the sensors


Pin Name Function

VCC Power supply (usually 5V)

GND Ground

AO Analog output (varies with gas)

DO Digital output (based on threshold via onboard potentiometer)


Basic Programming codes and syntax
Basic setup and loop
void setup() {
// runs once
Serial.begin(9600); // open serial at 9600 bps
}

void loop() {
// runs repeatedly
Serial.println("Hello World!");
delay(1000); // wait for 1 second
}

Digital I/O (LED, Button)


// Define the digital pins for the LED and button
#define ledPin 13 // Pin connected to LED
#define buttonPin 7 // Pin connected to push button

void setup() {
// Set LED pin as OUTPUT because we want to control the LED
pinMode(ledPin, OUTPUT);

// Set button pin as INPUT because we want to read its state


pinMode(buttonPin, INPUT);
}

void loop() {
// Read the current state of the button (HIGH or LOW)
int buttonState = digitalRead(buttonPin);

// Check if the button is pressed


if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn ON the LED
} else {
digitalWrite(ledPin, LOW); // Turn OFF the LED
}

// Small delay to prevent flickering or bouncing


delay(50);
}
Basic sensor Reading(MQ/LDR/Analog Sensors)
// Define the analog pin where the sensor is connected
int sensorPin = A0;

void setup() {
// Start serial communication with the computer at 9600 bits per second
Serial.begin(9600);
}

void loop() {
// Read the analog value from the sensor (range: 0 to 1023)
int sensorValue = analogRead(sensorPin);

// Convert the analog value to voltage (assuming 5V system)


float voltage = sensorValue * (5.0 / 1023.0);

// Print the raw value and voltage to Serial Monitor


Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.print(" | Voltage: ");
Serial.println(voltage);

// Wait for 1 second before reading again


delay(1000);
}

ESP32/ESP8266 WiFi Connection Code with Explanation


// Include the WiFi library
// Use <WiFi.h> for ESP32 or <ESP8266WiFi.h> for ESP8266
#include <WiFi.h>

// Replace with your actual WiFi network credentials


const char* ssid = "Your_SSID"; // WiFi name (SSID)
const char* password = "Your_PASSWORD"; // WiFi password

void setup() {
// Start the Serial Monitor to view debug messages
Serial.begin(115200);

// Begin WiFi connection using provided credentials


WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");

// Wait in a loop until the device connects to WiFi


while (WiFi.status() != WL_CONNECTED) {
delay(500); // Wait half a second
Serial.print("."); // Show connection progress
}

// WiFi connected successfully


Serial.println("\nConnected to WiFi!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP()); // Display the IP address assigned
}

void loop() {
// Keep empty or use for other tasks after WiFi is connected
}

ESP + HTTP GET Request to Send Data to a Server


#include <WiFi.h> // ESP32 WiFi Library
#include <HTTPClient.h> // Used to make HTTP requests

const char* ssid = "Your_SSID"; // WiFi name


const char* password = "Your_PASSWORD"; // WiFi password

void setup() {
Serial.begin(115200); // Start serial for debugging
WiFi.begin(ssid, password); // Start WiFi

// Wait for WiFi connection


while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}

Serial.println("Connected to WiFi!");

// Once connected, prepare and send an HTTP GET request


if (WiFi.status() == WL_CONNECTED) {
HTTPClient http; // Create HTTP object
// URL to send data (change this to your API/endpoint)
String serverUrl = "http://example.com/data?value=123";
http.begin(serverUrl); // Start the HTTP request

int httpCode = http.GET(); // Send GET request

// Check for successful response


if (httpCode > 0) {
String payload = http.getString(); // Read server response
Serial.println("Server Response:");
Serial.println(payload);
} else {
Serial.println("HTTP request failed");
}

http.end(); // Close the HTTP connection


}
}

void loop() {
// Repeat the GET request every 10 seconds
delay(10000);
}

ESP32 with MQ-2 or MQ-135 (Analog Sensor Reading)


int mqPin = 34; // Analog pin on ESP32 (GPIO34, input-only)

void setup() {
Serial.begin(115200); // Begin Serial for monitoring
}

void loop() {
int sensorValue = analogRead(mqPin); // Read gas sensor value

// Convert to voltage (if using 3.3V ESP32)


float voltage = sensorValue * (3.3 / 4095.0); // 4095 = 12-bit ADC on ESP32

Serial.print("MQ Sensor Value: ");


Serial.print(sensorValue);
Serial.print(" | Voltage: ");
Serial.println(voltage);

delay(1000);
}

You might also like