Search This Blog

Showing posts with label ESP8266. Show all posts
Showing posts with label ESP8266. Show all posts

Wednesday, 20 November 2024

PWM Motor Control: control the power supplied to a load by varying the width of the pulses in a digital signal

 

Beginner Embedded C++ Project: PWM Motor Control



Introduction

Pulse-width modulation (PWM) is a technique used to control the power supplied to a load by varying the width of the pulses in a digital signal. This allows us to control the speed and direction of a DC motor.

Uses of this Project

  • Control the speed of a fan
  • Control the direction of a robot
  • Dim the brightness of an LED

Requirements

  • A microcontroller with a PWM peripheral
  • A DC motor
  • A motor driver (if the motor requires more current than the microcontroller can provide)
  • Some wires

Code


// Define the PWM pin
const int pwmPin = 9;

// Define the motor driver pins
const int motorA = 10;
const int motorB = 11;

void setup() {
  // Set the PWM pin to output mode
  pinMode(pwmPin, OUTPUT);

  // Set the motor driver pins to output mode
  pinMode(motorA, OUTPUT);
  pinMode(motorB, OUTPUT);
}

void loop() {
  // Set the duty cycle of the PWM signal to control the speed of the motor
  analogWrite(pwmPin, 128);

  // Set the direction of the motor by setting the motor driver pins
  digitalWrite(motorA, HIGH);
  digitalWrite(motorB, LOW);

  // Delay for 1 second
  delay(1000);

  // Reverse the direction of the motor
  digitalWrite(motorA, LOW);
  digitalWrite(motorB, HIGH);

  // Delay for 1 second
  delay(1000);
}

Conclusion

PWM motor control is a powerful technique that can be used to control the speed and direction of a DC motor. This project is a great way to learn how to use PWM and get started with embedded C++ development.

```

**PWM Motor Control: A Beginner Embedded C++ Project** Pulse-width modulation (PWM) is a technique used to control the power supplied to a load by varying the width of the pulses in a digital signal. This allows us to control the speed and direction of a DC motor. This beginner-friendly Embedded C++ project will guide you through the steps of controlling a DC motor using PWM. You will learn how to set up the hardware, write the code, and control the motor's speed and direction. **Requirements:** * Microcontroller with PWM peripheral * DC motor * Motor driver (if required) * Wires **Benefits:** * Learn the basics of PWM * Gain hands-on experience with embedded C++ * Control the speed and direction of a DC motor This project is suitable for beginners with basic knowledge of electronics and programming. It is a great way to get started with embedded C++ development and learn a valuable technique for controlling motors.

Monday, 18 November 2024

Get started with embedded systems development | Micropython to control hardware

 

Micropython Tutorial: Getting Started

Introduction

Micropython is a compact and efficient implementation of the Python programming language designed for microcontrollers. It combines the ease of use and readability of Python with the low-level control and hardware access capabilities of microcontrollers, making it an ideal choice for embedded systems development.

Uses of Micropython

  • Rapid prototyping of embedded systems
  • Data acquisition and processing
  • IoT device development
  • Robotics and automation
  • Wearable device development

Requirements

  • A microcontroller board with Micropython support (e.g., ESP32, Raspberry Pi Pico)
  • A text editor or IDE (e.g., Thonny, Mu)
  • A USB cable for connecting the microcontroller board to your computer

Getting Started

To get started with Micropython, follow these steps:

  1. Install Micropython on your microcontroller board.
  2. Connect the microcontroller board to your computer using a USB cable.
  3. Open a text editor or IDE and create a new file.
  4. Write your Micropython code in the file.
  5. Save the file and transfer it to your microcontroller board.
  6. Run your Micropython program on the microcontroller board.

Basic Syntax

Micropython's syntax is very similar to Python's. Here are some of the basic syntax elements:

  • Variables are declared without a type and can be assigned any value.
  • Statements end with a newline character.
  • Indentation is used to group statements into blocks.
  • Comments start with a hash symbol (#).

Example Code

Here is a simple Micropython program that blinks an LED:

import machine led = machine.Pin(13, machine.Pin.OUT) 
while True: 
 led.on() 
 time.sleep(1)  
 led.off() 
 time.sleep(1)

Conclusion

This tutorial provides a comprehensive introduction to Micropython. By following the steps outlined in this tutorial, you can get started with Micropython and start developing your own embedded systems projects.

```

**Micropython Tutorial:** Micropython is a powerful and easy-to-use programming language for microcontrollers. It combines the simplicity of Python with the low-level control of microcontrollers, making it an ideal choice for embedded systems development. This comprehensive guide covers everything you need to get
, how to use it to control hardware, and how to develop IoT applications. Whether you're a beginner or an experienced programmer, this guide will help you get the most out of Micropython and start building your own embedded systems projects. **Key Features:** * Step-by-step instructions for getting started with Micropython * Coverage of all the essential Micropython concepts * Examples and exercises to help you learn * Troubleshooting tips and tricks **Benefits:** * Learn how to use Micropython to control hardware * Develop IoT applications with Micropython * Get started with embedded systems development * Build your own custom projects with Micropython

how to connect a temperature sensor to your Raspberry Pi and display the current temperature on a screen or console

Raspberry Pi Temperature Sensor Tutorial



In this tutorial, we'll show you how to connect a temperature sensor to your Raspberry Pi and display the current temperature on a screen or console.

Materials

  • Raspberry Pi
  • Temperature sensor (e.g., DS18B20)
  • Breadboard
  • Jumper wires

Wiring

Connect the temperature sensor to the Raspberry Pi as follows:

  • VCC (red wire) to 3.3V
  • GND (black wire) to GND
  • DATA (yellow wire) to GPIO4

Code

We'll use the following Python code to read the temperature from the sensor and display it on the console:

import os
import time

# Define the GPIO pin number connected to the temperature sensor
GPIO_PIN = 4

# Define the function to read the temperature from the sensor
def read_temperature():
    # Open the temperature sensor file
    with open("/sys/bus/w1/devices/28-00000569653b/w1_slave") as f:
        # Read the first line of the file
        line = f.readline()

        # Split the line by the equals sign
        parts = line.split("=")

        # The temperature is the second part of the split line
        temperature = float(parts[1]) / 1000

        # Return the temperature
        return temperature

# Main program
try:
    while True:
        # Read the temperature from the sensor
        temperature = read_temperature()

        # Print the temperature to the console
        print("Current temperature: {} degrees Celsius".format(temperature))

        # Wait for 10 seconds before reading the temperature again
        time.sleep(10)
except KeyboardInterrupt:
    # Exit the program when the user presses Ctrl+C
    pass
    

Next Steps

Now that you have a basic temperature sensor working, you can use it to build more complex projects, such as:

  • A weather station that displays the temperature, humidity, and barometric pressure
  • A home automation system that turns on the air conditioning when the temperature gets too high
  • A science experiment that measures the temperature of different objects

Troubleshooting

  • If you're not getting any readings from the temperature sensor, check your wiring and make sure that the sensor is properly connected to the Raspberry Pi.
  • If you're getting incorrect readings, try recalibrating the sensor by following the instructions in the sensor's datasheet.

Sunday, 17 November 2024

Detecting EMF (Electromagnetic Fields) with NodeMCU or ESP8266: A Ghost Detection Project

Detecting EMF (Electromagnetic Fields) with NodeMCU or ESP8266: A Ghost Detection Project



Electromagnetic Field (EMF) detection is a topic of interest both in scientific and paranormal circles. In this tutorial, we'll use a NodeMCU or ESP8266 to detect EMF, which some people believe may be useful in identifying unusual activity, such as ghostly presences. We'll create a simple project that uses an EMF sensor to measure the electromagnetic environment and monitor any fluctuations that could indicate an anomaly.

What You’ll Need:

  1. NodeMCU or ESP8266: This microcontroller will be used to read sensor data and connect to the internet for data monitoring.
  2. EMF Sensor (e.g., MX-03 or similar): This sensor detects the strength of electromagnetic fields around it.
  3. Jumper wires
  4. Breadboard
  5. Power supply for NodeMCU (can be USB or external adapter)
  6. Arduino IDE: To program the NodeMCU.

Circuit Diagram:

  • NodeMCU/ESP8266 Pinout:
    • VCC of EMF sensor to 5V (NodeMCU 5V pin).
    • GND of EMF sensor to GND (NodeMCU GND pin).
    • Signal Pin of EMF sensor to A0 (Analog Pin) of the NodeMCU.

Steps for Implementation:

1. Set up the Arduino IDE:

  • Open the Arduino IDE and make sure you have the ESP8266 board selected:
    • Go to File → Preferences → Additional Boards Manager URLs and add the ESP8266 board URL if not already added: http://arduino.esp8266.com/stable/package_esp8266com_index.json
    • Then go to Tools → Board → ESP8266 Board, and select NodeMCU 1.0 or Generic ESP8266 Module.
  • Install the necessary libraries for ESP8266.

2. Connect the EMF sensor:

  • Connect the EMF sensor to the NodeMCU as described above.
  • Make sure the Signal Pin from the EMF sensor is connected to the A0 pin on the NodeMCU for analog readings.

3. Write the Code:

cpp
// EMF Detection Code for NodeMCU / ESP8266 #include <ESP8266WiFi.h> // Library for WiFi connection #include <ESP8266HTTPClient.h> // Library for HTTP requests (optional, for sending data to a web server) const char* ssid = "Your_SSID"; // Your Wi-Fi SSID const char* password = "Your_PASSWORD"; // Your Wi-Fi Password int EMF_SENSOR_PIN = A0; // Analog pin where the EMF sensor is connected int EMF_THRESHOLD = 600; // Threshold for detecting "ghostly" activity (adjust this value based on testing) int emf_value = 0; WiFiClient client; void setup() { Serial.begin(115200); // Connecting to Wi-Fi Serial.println(); Serial.print("Connecting to WiFi"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected to WiFi!"); } void loop() { // Read the analog value from the EMF sensor emf_value = analogRead(EMF_SENSOR_PIN); // Print the sensor value to the serial monitor Serial.print("EMF Value: "); Serial.println(emf_value); // If the EMF value exceeds the threshold, alert the user (possibly ghostly activity detected!) if (emf_value > EMF_THRESHOLD) { Serial.println("Warning: High EMF detected! Possible paranormal activity."); // You can add an HTTP request to send data to a web server (for logging) // HTTPClient http; // http.begin("http://your-server.com/log"); // Replace with your server's URL // http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // String payload = "emf_value=" + String(emf_value); // int httpCode = http.POST(payload); // http.end(); } else { Serial.println("EMF level is normal."); } delay(1000); // Delay for 1 second }

4. Upload and Test:

  • Upload the code to the NodeMCU via the Arduino IDE.
  • Open the Serial Monitor to view the readings from the EMF sensor.
  • Move the sensor around different areas to observe how the readings fluctuate. You may notice stronger readings near electronic devices or areas with higher ambient EMF.
  • If the sensor detects high levels of EMF (above the set threshold), it will print a warning message to the Serial Monitor.

Testing and Calibration:

  • Test the Sensor: Place the sensor in various environments, including near electronic devices, lights, or other sources of EMF. The readings should fluctuate.
  • Ghost Detection: Set a higher threshold value (EMF_THRESHOLD) to determine when an anomalous reading occurs, which you could attribute to "ghostly activity" in this fun project.

Optional Enhancements:

  • Wi-Fi Integration: Send data to an online server (using an HTTP POST request as shown in the code). You could log the data for long-term monitoring or alert notifications.
  • Mobile App: Create a simple mobile app or web page to display real-time EMF data from your NodeMCU via Wi-Fi.
  • Sound or LED Alerts: Use an LED or buzzer to create an alert when EMF levels exceed the threshold.

Conclusion:

With just a few simple components, you can build a basic EMF detection device using NodeMCU or ESP8266. While this project is a fun way to explore the intersection of technology and paranormal investigation, it's also an excellent way to learn more about analog sensors, Wi-Fi integration, and real-time data monitoring. Remember, EMF detection is often used in scientific studies, but it’s also a popular tool in ghost hunting circles.

This setup can be expanded into various other IoT projects, such as sending data to cloud platforms or creating a more detailed system for detecting environmental changes in different areas.

Wednesday, 8 May 2024

Blink an LED using RaspberryPi pico,nano,3,4,b,b+ in Python and C/C++ both

 

How to Blink an LED on a Raspberry Pi

How to Blink an LED on a Raspberry Pi - Jeremy Morgan's Tech Blog 

The blinking LED is the “hello world” of the maker community, and today I’ll show you how easy it is to do with the Raspberry Pi 2 (or Model B)! We’re going to use Python and WiringPi for this project.

What you’ll need

For this article I’m using a Raspberry Pi 2, but you can also use a Raspberry Pi Model B. You will also need:

  • A GPIO Adapter
  • Breadboard
  • Resistor
  • LED
  • The quickest way to get that LED to blink is to take a look at the pins of the GPIO 

    Raspberry gPIo - learn.sparkfun.com

     and decide which one to tie to. Then you can use Python and the Raspberry Pi GPIO Library to create a script to light it up.

    import RPi.GPIO as GPIO ## Import GPIO Library
    import time ## Import 'time' library (for 'sleep')

    blue = 7 ## These are our LEDs
    ourdelay = 1 ## Delay
    # pins 4,17,18,21,22,23,24,25

    GPIO.setmode(GPIO.BOARD) ## Use BOARD pin numbering
    GPIO.setup(pin, GPIO.OUT) ## set output

    ## function to save code

    def activateLED( pin, delay ):
    GPIO.output(pin, GPIO.HIGH) ## set HIGH (LED ON)
    time.sleep(delay) ## wait
    GPIO.output(pin, GPIO.LOW) ## set LOW (LED OFF)
    return;

    activateLED(blue,ourdelay)

    GPIO.cleanup() ## close down library
    
    

    As you can see in the code above, it doesn’t take much to get things working. But I’ll explain the code a little deeper.

    import RPi.GPIO as GPIO
    import time

    The following code imports the Python GPIO library, and the time library. The GPIO library, as you probably guessed is the library for interacting with the GPIO in Python. It does an amazing job of simplifying the process. The time library is there so we can put a delay in, otherwise the blink might be too fast to notice.

    blue = 7
    ourdelay = 1

    Here I created a variable named “blue” (the color of the LED) and assigned it “7” which is the pin number we want. If I wanted to add multiple LEDs I could name it something like:

    blue = 7
    red = 13
    green 14

    I then created a “delay” variable of one second. This way I can change the delay of the lights blinking however I want.

    You can name the variables anything you want, but this was just to make it easy to see which LED is which if I wanted to do some fancy light show.

    GPIO.setmode(GPIO.BOARD) 

    Then, we set the GPIO mode to “Board” which means we’ll use the numbering of the pin by board instead of GPIO. This makes it a little easier to understand when using a bread board.

    With this line of code we set the pin to be an output:

    GPIO.setup(pin, GPIO.OUT)

    There are 2 main commands to turn the LED on then off:

    GPIO.output(pin, GPIO.HIGH)
    GPIO.output(pin, GPIO.LOW)

    If you wanted to blink an LED twice you would have to repeat the last two lines each time. So I decided to put this in a function and put the pin and delay as parameters. This way making a particular LED blink is as simple as:

    activateLED(blue,ourdelay)

    This is repeatable and saves code when doing larger programs.

    To close everything down, we need to run the following:

    GPIO.cleanup()

    It’s that easy! You could easily write a nice Python script that do some pretty cool stuff with just a few lines of code.

     

    For this step we’ll install WiringPi for the libraries to interact with the GPIO. This allows us to do what we just did, but from the command line. We’ll need to install WiringPi:

    cd ~/sources
    git clone git://git.drogon.net/wiringPi
    cd wiringPi
    git pull origin
    ./build
    
    

    If successful you should see a screen like this:

    Blink an LED Raspberry Pi

    Now we can light up the LED from the command line. Remember the pin 7 in the example above? We can now light up like so:

    gpio mode 7 out
    gpio mode 7 1
    
    

    This will light up the LED. You can turn it off by entering:

    gpio mode 7 0
    
    

    Blink an LED Raspberry Pi

    This makes it super easy to light up LEDs from the command line. You could create a pretty neat BASH script to do this, and do some neat things, or call this from other languages.

    Summary

    I hope this has helped in showing how easy it is to blink an LED on the Raspberry Pi 2/B. Of course as you progress on you’ll want to do far more than just blink an LED, but the GPIO libraries make it very easy to create some neat stuff. If you’ve experimented with this and done something cool, Let me know!!!


Saturday, 2 December 2023

What is Difference in Node MCU and Arduino, IOT Development Boards

Introduction:

NodeMCU and Arduino are both popular platforms for building DIY electronics projects, but they have some key differences in terms of their hardware, programming languages, and use cases.

NodeMCU:

NodeMCU is a development board that utilizes the ESP8266 WiFi module.

It includes a built-in USB-to-Serial converter, allowing easy programming and communication with a computer.





Programming Language:

NodeMCU is typically programmed using the Lua scripting language, though it also supports Arduino IDE with additional ESP8266 board support.

Lua is a lightweight scripting language, and it is often used in embedded systems.


Wireless Connectivity:

NodeMCU is designed with a focus on wireless connectivity, making it well-suited for IoT (Internet of Things) projects.

It has built-in WiFi capabilities, enabling it to connect to the internet and communicate with other devices.


Use Cases:

Commonly used for IoT projects, home automation, and projects that require wireless communication.

Suitable for applications where internet connectivity and real-time data transfer are essential.


Arduino:

Arduino is an open-source electronics platform that can use various microcontrollers. The most popular one is the AVR-based Arduino boards, but there are also Arduino boards based on other microcontroller architectures, such as ARM.

Arduino boards do not typically have built-in WiFi capabilities.




Programming Language:

Arduino is typically programmed using the Arduino IDE, which uses a simplified version of C/C++.

The Arduino IDE abstracts away some of the complexities of low-level programming, making it beginner-friendly.


Connectivity:

Arduino boards can connect to the internet using shields or modules (e.g., Ethernet shields, WiFi modules), but this requires additional hardware.

Arduino boards are often used for a wide range of electronics projects, from simple LED blinking to more complex robotics.


Use Cases:

Well-suited for a broad range of applications, from simple electronic projects to robotics and automation.

Arduino is commonly used for educational purposes due to its simplicity and ease of use.


Comparison:

Complexity:

NodeMCU can be more complex due to its focus on internet connectivity and the Lua programming language.

Arduino is often considered more beginner-friendly with a simpler programming environment.


Connectivity:

NodeMCU excels in projects that require wireless communication and internet connectivity out of the box.

Arduino can handle a variety of projects but may require additional components for internet connectivity.


Programming Language:

NodeMCU primarily uses Lua (can be programmed in C++ Also) , while Arduino uses a simplified version of C/C++.

In summary, NodeMCU and Arduino are both versatile platforms, but the choice between them depends on the specific requirements of your project, your familiarity with the programming languages, and your preference for built-in wireless capabilities.

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...