Hello friends, I hope you all are having fun. Today, we are going to share the 7th tutorial of Section-III in our Raspberry Pi Programming Course. In the last tutorial, we interfaced a DHT11 sensor with Raspberry Pi 4. Today, we are going to interface another temperature sensor i.e. DS18B20 with Raspberry Pi 4.
DS18B20 is a popular temperature sensor especially in severe/critical environments i.e. chemical plants, mines, industrial sites etc. because of its 1-wire operational technique and accurate readings up to 4 decimal digits.
Today, we will interface a DS18B20 temperature sensor with Raspberry Pi 4 and will display the values on a 16x2 LCD.
Let's have a look at the components required for this project:
Here's the list of components:
A waterproof variant of this sensor is also available, which encloses the sensor within a cylindrical metal tube. The sensor depicted in the above image will be used in today's project. The sensor's specifications are shown below.
A wide variety of temperature sensors are available. The following are the two most common kinds of temperature sensors:
Contact sensor: Some thermometers use direct contact with an object, referred to as "contact type temperature sensors," to measure the degree of warmth or cold.
Non-Contact sensor: This type of thermometer does not touch the object it is measuring; instead, it measures the temperature based on the radiation emitted from that object. DS18B20 is a non-contact temperature sensor.
Here's the circuit diagram of the DS18B20 temperature sensor and a 16x2 LCD display, connected with Raspberry Pi 4:
Now, let's design this circuit on a breadboard with the help of Jumper wires. When everything is connected, my hardware will look like this.
We have designed our circuit, so it's finally time to write the Python code for DS18B20 with Raspberry Pi 4:
Before start working on our code, we need to first install the LCD Python library and enable the 1-wire protocol in RPi board.
We need to install Raspberry Pi's Adafruit LCD library to display the temperature on the LCD screen. Using Adafruit's library, we can easily operate the LCD in 4-bit mode. So, follow the below instructions to install Adafruit Python Library:
Any project on GitHub can be cloned using Git. Since the library is hosted on Github, we'll need to set up a Git before installing this library.
That's all there is; the library should now be operational. In the same way, let's install the 1-wire library for DS18B20 sensor.
If we want to connect with the DS18B20 sensor via a One-Wire approach, we must have to enable the One-Wire Protocol in Raspberry Pi first. So, follow the below instructions:
This is what you can expect to see in your terminal windows:
You can see the sensor's readings on the terminal as a result of these commands. The image below shows a red arrow pointing to the temperature. The current temperature in my home is 37 degrees Celsius.
Here's the complete Python Code to display the temperature from DS18B20 on an LCD display with Raspberry Pi 4:
So, let's understand this Pi code for LCD display and One-Wire communication. I've broken down the code into smaller, more digestible chunks below to make it easier to understand.
DS18B20 Python Code Explanation
Importing the necessary header files is always the first step in a new program. Time and the LCD header are imported here to use the LCD with Pi.
It is important to mention the Display pins linked to the Raspberry GPIO. Consult the diagram above if you're unsure of the pin numbers for specific GPIO pins. Once the pins on the PI to which the LCD is connected have been declared, use these lines of code to initialize the LCD display.
Once the LCD has been initialized, we show a sample text message. To indicate a new line, the character 'n' is used. There is a delay of two seconds before users can begin reading the intro message.
Make sure you remember what you did in step 4 in order to enable the one-wire interface on your Pi. For this reason, we are using the os.system function to repeat the code. Afterwards, a file path is supplied where the temperature value will be read from. We can't open the folder since we don't know its exact name. The device folder variable connects to the '28-' folder using the * symbol. The temperature value is stored in a file with the name device file, which is also in that folder.
Then we create a get temp method, which specifies how to read the temperature from the file we previously linked. There will be a file containing the temperature data; however, the format will be as follows:
We only need the temperature value, which is 37000, from this. A reading of 37.00°C can be seen in this instance. After trimming all the unnecessary information from this type of text, we must next divide 37000 by 1000.
Using the lines variable, the file's lines can be parsed. A search for "t=" is done in these lines, and in the variable temp string, the value that comes after that letter is recorded. Finally, we perform division on the string value with 1000 in the variable temp c to obtain the temperature value. Finally, the code should output the temp c variable.
To display the current temperature on the LCD panel, we merely need to invoke the previously described function inside the infinite while loop. Every second, we refresh the LCD display to show the current value.
Use the code provided at the end of this page to compile it on your Raspberry Pi and see what happens. Before running the application, Install the display libraries and enable a one-wire connection on the Pi. You can now run the application and see if everything went well; if so, the intro text should be visible. Adjust the contrast potentiometer, if necessary. What you'll see when it's all done is shown in the below images:
Temperature sensors can be used in a variety of ways, so here are some examples.
In this lesson, we have studied how to use Raspberry Pi's GPIO pins to connect DS18B20. In addition, we looked into the sensor's fundamental principles and current-day usefulness. We also designed a circuit that we later programmed to collect temperature readings using the temperature sensor and perform a little calculation and display it on the LCD screen in degrees Celsius. In the next tutorial, we will interface the BMP180 Air Pressure sensor with Raspberry Pi 4. So, stay tuned. Have a blessed day.
Hello friends, I hope you all are doing great. Today, I am going to share the 6th tutorial of Section-III in the Raspberry Pi Programming Course. In our previous tutorial, we have seen how to interface an Ultrasonic Sensor with Raspberry Pi 4 and used Python to perform its calculations. In today's tutorial, we'll discuss how to interface a DHT11 temperature and humidity sensor to a Raspberry Pi.
So, let's get started:
Here's the list of components, we are going to use in today's circuit:
DHT11 is a low-cost digital sensor, used to measure temperature and humidity in the surroundings. DHT sensor has three main components i.e.
Now, let's have a look at the Pinout of DHT11 sensor:
DHT11 has 4 pins in total, which are:
The DHT11 timing diagram is shown in the below figure:
This device uses a thermistor to monitor temperature and a capacitive humidity sensor to measure relative humidity. A humidity-detecting capacitor's electrodes are separated by a dielectric substrate that retains moisture. When the humidity level fluctuates, the capacitance value changes as well. Analog resistance values are measured, processed, and stored by the IC, which then translates them into digital values.
The resistance value of this sensor is monitored, as it warms up using a negative temperature coefficient thermometer(NTC). This sensor is commonly made of semiconductor ceramics in order to achieve a higher resistance value even at the smallest temperature change.
With a 2°C precision, the DHT11's temperature range is 0 to 50 degrees Fahrenheit. This sensor can accurately monitor humidity levels from 20% to 80% with a 5% degree of precision. One reading per second, or 1Hz, is the sampling rate of this sensor. The microcontroller DHT11 has a power consumption of 3 to 5 volts. The maximum amount of current that can be drawn during a measurement is 2.5 mA.
The sensor and the microcontroller are connected via a 5K to 10K ohm pull-up resistor.
There are many types of temperature sensors available. Factors involved in selecting a correct sensor are: what we're measuring, how precise we need it to be, and where we're taking the readings. The Negative Temperature Coefficient (NTC) thermistor, thermocouple, semiconductor sensors, and Resistance Temperature Detector(RTD) are the most commonly used temperature sensors.
With its dual-row flat, no-lead SMD design, Grove's new AHT20 temperature and humidity sensor is ideal for use in reflow soldering applications. In addition to the standard temperature sensor, the AHT20 has a capacitive humidity sensor made by MEMS semiconductors that is more accurate than the standard sensors.
Digital sensors can monitor temperature as well as relative humidity. Two measurements are converted into a digital signal via an analog-to-digital converter chip. Temperature sensors with long-term stability and great performance are among the most popular.
Both temperature and humidity are monitored by the DHT22, quite similar to DHT11. The DHT22 costs a little more because it has a wider temperature and humidity range than DHT11, making it more precise. In terms of how it's handled and coded, the DHT22 is identical to DHT11. A temperature sensor that performs better and is more accurate should definitely be considered.
When compared to the DHT series, the BMP280 has the capability to measure both temperature and barometric pressure. You can use this in both SPI and I2C modes, making it an upgrade from the BMP180. Because the air pressure changes with elevation, it can estimate a location's altitude as well.
While the BMP280 only monitors temperature and air pressure, the BME280 has a humidity measurement in addition.
DS18B20 is a one-wire temperature sensor and gives accurate values up to 4 decimal digits.
AF5485 is a small and light-weight sensor but it has an impressively complex internal system that allows it to provide the best accuracy. Building automation, weather stations, and temperature monitoring are just a few possible applications.
Compact and lightweight, the AM2311A is an auto-calibration module that consumes minimal power. Furthermore, it is capable of transmitting data at distances greater than 20 meters. It goes without saying that this sensor is extremely dependable and stable over the long run. As a result, it can be employed in a variety of settings.
As you can see in the above figure, the circuit diagram is quite straightforward. To avoid noise in the DHT11 output, a 5K pull-up resistor is connected to the Data Pin. The temperature and humidity readings are transmitted as serial data through this pin.
We have also placed an LCD 16x2 to display the values. We have already discussed LCD Interfacing with RPi4, but in that tutorial, we used data pins to write on the LCD, but today, we will use an I2C LCD and send the data via I2C pins.
To connect the DHT11 sensor to the Raspberry Pi, the following steps must be followed.
Now, Raspberry Pi 4 has to be connected to the 16x2 LCD screen:
All our modules are powered up, so everything's correct. Now it's time to write the Python Code for getting DHT11 values and displaying them on the LCD screen:
We need to install the DHT11 Adafruit library to read the sensor values from Raspberry Pi 4.
Now let's design our Python code:
Here's the complete Python Code to read the data from the DHT11 sensor using Raspberry Pi 4:
Let's understand the code line by line:
Monitoring or controlling environmental quality is the main goal of environmental monitoring. The DHT11 humidity and temperature sensors are widely used in such systems.
Since this temperature sensor is inexpensive, it can be used in low-cost but effective weather stations that show the temperature and humidity of the surrounding environment.
Climate control is a method of managing the temperature. So, the DHT11 temperature and humidity sensors may be useful in ensuring that the environmental readings are accurate. Temperature and humidity sensors are sent to the microcontroller, and the system will respond if the temperature exceeds a predetermined upper or lower limit.
In this tutorial, we have studied how to connect a DHT11 sensor for humidity and temperature readings with Raspberry Pi 4. The sensor's principles and applicability in the current world were also studied. In the next tutorial, we'll learn how to interface DS18B20 with Raspberry Pi 4. So, stay tuned. Have a good day.
Hello friends, I hope you all are doing well. Today, I am going to share the 5th tutorial of Section-III in our Raspberry Pi Programming Course. In our previous tutorial, we have seen the interfacing of a PIR Sensor with Raspberry Pi 4. In today's tutorial, we will interface an Ultrasonic sensor with Raspberry Pi and will use Python to perform its calculations. So, let's get started:
Here's the list of components, we are going to use in today's project:
An Ultrasonic Sensor consists of a transmitter and a receiver, the transmitter emits the ultrasonic wave, which after hitting some object bounces back and receives by the ultrasonic receiver. If the Ultrasonic sensor is operated at 5V, it normally measures a distance of up to 450 centimeters.
With an ultrasonic sensor, you can measure the distance between your body and a target item, by sending and receiving ultrasonic sound waves. Unlike audible sounds, ultrasonic waves move faster. To create ultrasonic sound waves, the transmitter uses piezoelectric crystals. The sound then travels to and from the target. When it returns, the receiver gets the sound.
Mostly, ultrasonic sensors can detect objects as close as a few centimeters and as far as about five meters. Measurements of approximately 20 meters can be achieved with specially designed units.
An established technology, ultrasonic sensors have a wide range of uses, from industrial to consumer. Many new devices requiring presence detection or distance measuring can benefit from their simplicity, low cost, and durable construction. Because the hardware and software settings can be changed, they can be used in a wide range of situations.
The Ultrasonic Sensor has four connections:
An ultrasonic sensor is made up of two parts: a transmitter and a receiver, arranged side by side as close as possible. Smaller measurement errors are achieved when the receiver is near the emitter, as the path of sound from the source to the destination is straight-lined. In addition, the transmitter and reception functionalities of some ultrasonic transceivers are combined into a single device, decreasing inaccuracy to the greatest extent possible while simultaneously reducing the PCB footprint of the device.
Moving further away from the transmitter causes sound waves to broaden and the detection area increases. Ultrasonic sensors, instead of specifying a fixed detecting region, provide coverage specifications in the form of beam width or beam angle to account for this shifting terrain. For comparison, either the full beam angle or the difference from a transducer's straight line, is being used.
The beam angle has a secondary effect on the device's range. As shown in the above figure, in the case of a narrow beam, the energy of an ultrasonic pulse can travel farther, before it dissipates to unusable levels. Wide beams are better for broad detection and covering large regions, while narrow beams are better for preventing false positives, since they limit the detection region.
When looking for individual parts, transmitters and receivers for ultrasonic sensors can be found separately, or as part of a single device called an ultrasonic transceiver. In most analog ultrasonic sensor alternatives, a trigger signal is sent by the transmitter, and the receiver gets the signal as soon as the echo is recognized. In order to meet specific requirements, the designer can alter the pulse length and any encoding. The microcontroller is ultimately responsible for decoding and calculating the time between the trigger and the echo.
Ultrasonic sensors typically emit a chirp of ultrasonic radiation, that is much higher in frequency than the range of human hearing. This chirp is used to calculate the duration taken for sound to reflect from an item. This method is based on the principles of echolocation, which are used by bats to detect their prey. With this in mind, it is easy to convert the time of the ultrasonic chip to distance because the sound travels at 343 m/s in the air at ambient temperature. So, in order to calculate the distance covered, we will use the following formula:
We have divided it by 2 because the waves will cover the distance twice, one while going toward the object and the second while coming back from the object.
For example, an ultrasonic sensor emits an ultrasonic wave pointed toward a box. The waves take 0.025 seconds to bounce back. Now, in order to calculate the distance between the sensor and the box, we need to use the above formula and it gives us 4.2875 meters, as shown in the below figure:
As we discussed in the Pinout section, Ultrasonic Sensor has 4 pins in total.
If you set Vcc to 5 volts, the Echo pin will also output 5 volts. Raspberry Pi GPIO pins are prone to voltages above 3.3V, so it is imperative to avoid them. Two alternatives exist at this point:
Now let's design it with real hardware:
Double-time distance measurements are calculated with the following Python program:
For ten seconds, the trigger is engaged and the sensor uses this signal to produce sound pulses. The start time is decided as soon as the echo signal rises to a high level. Once the echo signal's negative edge is identified, the stop time is calculated. To calculate how long it will take for a sound wave to travel between two points, subtract the starting time from the final time. The speed of sound in the air is 343 m/s, so multiple this time is multiplied by the speed of sound. You must multiply the values by 100 in order to display them in cm. A speed of 34,300 cm/s is obtained. Finally, to acquire a single distance, divide everything by 2. Now let's implement this pseudocode in Python script:
When using the GPIO SetMode, the numbering scheme used to work on Raspberry Pi's GPIO can be defined in two ways: GPIO.board and GPIO.BCM, respectively.
If you want to learn more about GPIO.Board and BCM, I'd like you to check out the following picture.
It is important to take into account the limits of ultrasonic sensors before making a final decision on which sensor to use.
In this tutorial, we learned how to connect ultrasonic sensors to Raspberry Pi 4. In addition, we studied the sensor's fundamentals and the distance calculation etc. Next, we'll learn how to interface a DHT11 sensor with Raspberry Pi 4 board. Till then, take care. Have fun!!!
Hello friends, I hope you all are doing well. Welcome to the 11th tutorial of our Raspberry Pi programming course. In the previous chapter, we have seen how to regulate the speed of a Stepper motor with Raspberry Pi 4. Today, we'll work on the servo motor and will control it with RPi4. So, let's get started:
We will need the following components to control Servo Motor with Raspberry Pi 4:
The Tower Pro SG90 Servo Motor has 3 wires in total, which are:
Vcc and GND pins of the servo motor should be connected to the
power supply. The Servo Motor's Signal Wire should be connected to the Controller's GPIO Pin.
There are three wires in a standard servo motor: one for power control, one for ground, and one for neutral. Their intended purpose determines the size and shape of these motors.
There are unlimited possibilities in Robotics where we can use Raspberry Pi to control servo motors.
DC servo motors usually have separate DC sources for the stator and armature windings. The armature current and the field current can be controlled to get the desired result.
An AC servo motor, which incorporates an encoder, is employed for closed-loop control systems. This motor may be precisely positioned and regulated to meet the application's needs. Better bearings and higher tolerances are common in these motors, and higher voltages are sometimes used in simple designs to boost torque. When it comes to robotics, CNC machines, and other automated systems, servo motors are preferred because of their accuracy and precision.
It is the most commonly used servo motor and has a rotation of approximately 180 degrees. To keep the rotation sensor safe, it has physical brakes built into the gear mechanism. Many of these popular servos are used in radio-controlled water, radio-controlled automobiles, airplanes, robotics, toys, and many more applications.
Additional gears transform the servo motor output from circular motion to back-and-forth motion.
A servo mechanism consists of three main components i.e.
The servo motor uses a permanent magnet DC motor with an inbuilt tachometer to calculate the output voltage. The electronics drive provides motors with electrical power in response to tachometer feedback voltages. After setting a commanded speed using a closed velocity loop, the driver's circuitry compares the tachometer feedback voltage to the goal speed. The velocity loop monitors the tachometer feedback and the commanded velocity while the driver modulates the power in the motor.
A sophisticated servo motor system has multiple integrated loops configured to optimal performance for the most precise motion control. For current, velocity, and location, the system uses feedback loops with high precision. To adjust parameters in real-time, each loop notifies the next and checks the feedback elements.
The current loop, also known as the torque loop, is the foundation for all other loops. An electric motor's acceleration or thrust is determined by the relationship between current and torque (or force, in the case of a linear motor). A current sensor is a device that measures the amount of current flowing through the motor and communicates this information to the user. Control electronics frequently receive proportional signals via analog or digital techniques. Ordered signals are subtracted from this signal. The servo motor needs to run at the specified current for an extended period to keep the loop intact. It will then update at sub-second intervals until it reaches the desired current.
Similarly, the velocity loop works with a voltage proportional to velocity in the same method. At low velocities, the current loop receives a command from the velocity loop to increase voltage.
The velocity loop is fed a velocity command from a PLC or motion controller that supplies the required current for acceleration and deceleration of the motor. The servo mechanism is controlled precisely and smoothly by the three loops working together in perfect harmony.
It doesn't matter if it's brushed or brushless, rotatory, or linear. The servo system receives feedback from various sensors, i.e. potentiometers, encoders, linear transducers etc. This system's capabilities are rounded out by an electronic control system that verifies feedback data and command references to make sure the servo motor is performing as instructed. Multi-axis milling centers use brushless motors and motion control systems more complex than those used in recreational applications.
Pulse Width Modulation is required to operate a servo motor. The pulse's width or length controls the servo motor's shaft position when using the PWM approach.
There is a defined frequency for the PWM signal, determined by the type of Servo Motor being used. The PWM Frequency of our SG90 and MG90S Servo Motors is 50Hz.
A pulse width signal of one millisecond (one-thousandth of a second) sets the servo's position to the LEFT. This post has a duty cycle of 0.5 percent.
As with pulse widths of 1.5 and 2 microseconds, the servo is set to MIDDLE (7.5% duty cycle) and FAR RIGHT with a duty cycle of 10%.
Now let's design the Python code for Servo Motor Control using Raspberry Pi. We'll be using our favorite code editor, Thonny, so get it up and running on your Raspberry Pi:
Variable duties are defined and assigned random values, such as 2. When counting our intervals, it serves as the starting point.
After that, we'll run a for loop to find all the duty values between 2 and 17. Given the range of 2 to 17 as an interval, The motor will move the shaft if duty is increased by one every time the shaft moves. After every one-second interval, the shaft rotates 12 degrees to the right until it reaches 180 degrees.
You can experiment with multiple motors to see how much fun this can be. This project's complete source code can be seen below:
When it comes time to put the concept into action, we'll take advantage of Raspberry Pi's PWM functionality. If you've been following along, you know that the Servo Motor position changes depending on the PWM signal from the Raspberry Pi.
To achieve a sweeping effect from the Servo Motor, we need to alter the PWM signal's Duty Cycle between 5% and 10%, corresponding to the extreme left and right positions.
If you look at the code, you'll see that the duty cycle steadily increases from 5% to 10%, with a 0.5 percent increase at each stage. The reversal will commence as soon as it hits 10%.
Many applications can benefit from regulating the angle of rotation of the Servo Motor via the Raspberry Pi, such as:
It is impossible to find a radio signal, take pictures of a galaxy billions of light-years away, or photograph a live subject without using a servo motor.
It's all about safety while designing and implementing transportation networks for buildings. Servo motors are extensively used in elevators in some of the world's highest buildings to carry passengers safely and smoothly.
Robotics is a hot topic, and their practical applications are growing at an ever-increasing rate. Servo motors, which are compact, powerful, and precise due to their changing size and force density, are the most widely utilized in robotics. Using robots to control the detonation of bombs, autonomous firefighter trucks, or even the joints in robot arms is all possible.
To eliminate the risk of human error and speed up production, manufacturers are creating robotic alternatives. Another robot example is the pick and place robot, which can move items from one side of an industrial building to the other. Servo motors are commonly utilized when mobility or rotations could be hazardous.
Precision and power are critical features of servo motors, which are used in bending and cutting metal sheets and high-speed milling machines. Servo motors are commonly employed in the spinning sections of conveyor systems in various industries, such as the food and beverage industry.
Congratulations! You have made it to the end of this tutorial. We have seen how PWM is used to control a servo motor. A variety of servo motor designs and real-world applications have also been demonstrated and their application in real life. In the next tutorial, we will learn how to interface an LDR Sensor with Raspberry Pi 4. Thanks for reading. Have a good day.
Hello friends, I hope you all are having fun. Welcome to the 10th tutorial of our Raspberry Pi programming course. In the last chapter, PWM was utilized to regulate the DC motor's speed and direction with a motor driver L293D. In this chapter, we'll advance our skills with PWM and use it to control a stepper motor using the same motor driver L293D.
Here's the video demonstration of this project:
Let's get started:
Here's the list of components, which we will use to control the speed and direction of Raspberry Pi 4:
The Raspberry Pi with desktop is required for this project. An SSH connection can be made, or the RPi can be shown on an LCD screen with a keyboard, and mouse. (We discussed this in previous chapters)
We will use an L293D motor driver to control the direction and speed of the stepper motor. In our last lecture, we controlled the DC motor with the same driver i.e. L293D and I explained it's working & why we use it? in detail there. So, please check that tutorial out, if you are new to this motor driver.
The below figure shows the circuit diagram of Stepper motor interfacing with Raspberry Pi4:
The wire mappings from my Raspberry Pi 4 to a stepper motor driver are shown in the below diagrams:
Open Thonny text editor. Importing the GPIO and time modules is the first step. Make sure you type the GPIO module's name exactly, case-sensitively, on the first line.
Congratulations! You have made it to the end of this tutorial. We have seen how PWM is used with a motor driver IC to control a stepper motor. We have also seen different stepper motor control techniques, how to set up our circuit diagram, and how to write a Python program that controls the steps for our motor. In the next tutorial, we will have a look at how to control a Servo Motor with Raspberry Pi 4 using Python. Till then, take care and have fun !!!
Hello friends, I hope you all are doing well. Welcome to the 9th tutorial of our Raspberry Pi programming course. In the last chapter, we generated a PWM signal from our Raspberry Pi to control the brightness of an LED. We also studied different functions used in Python to perform PWM. In this chapter, we'll get a bit advanced with PWM and use it to control the speed and direction of a DC motor with the help of a motor driver IC.
To control the speed & direction of the DC Motor, we will:
We will use the following components to control the DC motor speed:
Pulse Width Modulation(we studied in the previous tutorial) will be used to regulate the speed of a DC motor. A quick recall, a PWM signal is used to generate a variable voltage at the output depending on the duty cycle. The duty cycle refers to the length of time during which the signal is kept at a high level and determines how much power is given to the signal.
As a result of the PWM signal, the speed of a DC motor can be controlled in a non-resistive or non-dissipative manner.
The L293D pinout is shown in the following diagram.
The microcontrollers provide either 5V or 3.3V at their GPIO Pins, in the case of RPi4, it's 3.3V. The current rating of these GPIO pins is normally 10-50mA, which is quite low and it's justifiable as their sole purpose is to send the signal.
Now if we talk about DC Motors, they normally operate at 5V-48V and have a current rating from 100mA to 10A. So, we can't connect a DC motor directly to a microcontroller's pin. We need a motor driver to amplify the voltage and current.Moreover, DC motors also produce back EMF, which may burn the GPIO, so in order to protect the board, we should have a motor driver in between.
We have designed the circuit in the above section and now it's time to get our hands on Python code. We will be using the Thonny IDE in Raspberry Pi 4.
In this code, we will write a simple code to drive the motor forward for 5 seconds, then backward for another 5 seconds at a 50% duty cycle. You can alter any of these values as you see fit.
I will explain the code line by line for better understanding:
Motors from the DC series are commonly employed in electric locomotives and fast transit systems, as well as trolley vehicles. Because of their high starting torque, they're also found in cranes, hoists, and conveyors.
The use of DC shunt motors in rolling mills is due to their ability to accurately manage speed. They're used for driving lathes at a fixed speed, used in reciprocating and centrifugal pump drives, and also used in blowers, machines, and reciprocating pumps.
They can be found in a wide variety of machinery, including elevators, conveyors, heavy planers, shears, and punches, as well as intermittently high torque loads and air compressors.
Congratulations! You have made it to the end of this tutorial. We have seen how PWM is used with a motor driver IC to control a DC motor's speed and direction. In the next tutorial, we will have a look at how to Control a Stepper Motor with Raspberry Pi 4 using Python. Till then, take care. Have fun !!!
Hello friends, I hope you all are doing great. It's the 8th tutorial in our Raspberry Pi programming course. In the previous lectures, we interfaced LCD 16x2 and Keypad 4x4 with Raspberry Pi 4. In this chapter, we are not going to interface any external module with Pi, instead, we'll create a PWM signal in the raspberry pi using Python. Let's get started:
We are going to use the below components in today's PWM project:
Before going forward, let's first understand what is PWM:
Let's understand the working of PWM with an LED example. We can change the brightness of an LED using PWM. If we provide +5V, the LED will have full brightness, but if we provide +2.5V to the LED, its brightness will fade. We achieve +2.5V from a +5V signal by turning it ON and OFF continually. So, in a signal of 1 sec, if we turn it ON and OFF 100 times, the overall power of the signal will be halved as it's in an OFF state for 50% of the duration. This process is called Pulse Width Modulation(PWM).
The percentage for which the signal remains in the ON state during one cycle is called the duty cycle.
To get an ideal square wave, you need a duty cycle of 50%. The signal is always on(full-scale) with a 100% duty cycle, while the signal is always off(Ground) with a 0% duty cycle.
The inverse of the period is the frequency of the signal, which is the number of times a periodic change is accomplished per unit of time. Speed is determined by how quickly a signal goes from high to low i.e. how quickly a PWM completes a cycle. Constant voltage output is achieved by continually turning the digital signal on and off at a high frequency.
The 'PWM resolution' refers to the degree of control over the duty cycle. The more 'brightness' levels we can display, the greater our PWM resolution needs to be. Pprecise microcontroller timing is required because the duty cycle is normally around 50Hz. The more powerful the microcontroller, the shorter the time intervals it can keep track of. The microcontroller must not only time the 'interrupt,' which generates the pulse but also run the code that controls the LED output, which must be completed before the next interrupt is called, which is another limiting issue. It's also likely that you'll want your microcontroller to accomplish activities other than controlling the brightness of the LEDs, so you'll need some spare execution time between interrupts.
The fundamental benefit of greater PWM resolutions for LED PWM control is that it reduces the difference between 'off' and the LED's lowest achievable brightness. Suppose we have a duty cycle of 20,000 microseconds and a resolution of 10,000 microseconds. In that case, the difference in brightness between "off" and the lowest possible brightness will be 50 percent of the total brightness. The difference would be 10% at a resolution of 2,000 microseconds. The "PWM resolution" determines the number of brightness levels that we can support between 0% and 100% when it comes to brightness levels. (100 percent). Again, the better the resolution, the more precise the timing, and the more computing power is needed to process the information.
The above diagram shows a PWM resolution of 10%.
Depending on the nature of your application, the resolution and overall duty cycle requirements may be different. There is no need for precision control for simple displays; nevertheless, the ability to manage the brightness level may be crucial (think of the issue of mixing colors using an RGB LED, for example). More control and accuracy necessitate more microcontroller resources; thus, the trade-off is straightforward.
Even though hardware PWM is the preferred approach for generating PWM from the Raspberry Pi, we will use software PWM in this article.
Pins 2 and 6 of the Pi board can be used to supply the circuit with Vcc and ground.
The thorny Python IDE on raspberry pi will be used here to write our Python script. If you haven't already done so, please go back to Chapter 4 and read about how to get started with this IDE before reading on.
To keep things simple, we'll create a file called PMW.py and save it to our desktop.
We're using a 50 Hz software PWM signal to generate a customized sine wave with RPi. It has a 20-millisecond window at this frequency. During the application, the frequency does not fluctuate.
Increasing the software PWM duty cycle from 0 to 100 is required to produce a rectified sine wave. The PWM signal is applied to the LED in five-pulse trains every 0.1 seconds, with each train lasting 0.1 seconds.
As a result, the duty cycle is lowered from 100 to 1 in steps of minus one. Five PWM pulse trains, each lasting 0.1 seconds, are applied to each increment. Iteration continues indefinitely until a keyboard interrupt is received, at which point the user program terminates.
Import RPi.GPIO then time libraries. Then a simple script is run to begin. The GPIO.setwarnings() method is used to disable the warnings.
To set the RPi's PINs to the number of board, use the GPIO.setmode() function to set the pin numbering. The GPIO.setup() method configures pin 40 of the board as an output. However, the GPIO.PWM() technique is used to instantiate board pin 40 as a software PWM.
It is possible to write a user-defined setup() function to ensure that the software PWM has no duty cycle when it is first started. Only one instance of this function is ever called.
The duty cycle of the PWM signal is altered from 0 to 100 and then back to 0 in a user-defined loop() function. This occurs in increments of one, with a 0.1-second gap between each. For an endless number of times, the LED lights up and fades back down.
The PWM signal is turned off when a keyboard interrupt is received by calling the endprogram() method. The GPIO of the Raspberry Pi is then wiped clean.
Setup() and loop() are the two methods in a try-exception statement, and they are each called once.
A PWM instance can be created with the help of this function. This is a two-step process:
The syntax for this method is:
The number of the channel must be given in accordance with the user-Board program or BCM numbering.
This technique can be used with a PWM software instance. PWM duty cycle is all you need to know about this.
PWM instances can be accessed by calling this method from a Python program. A software PWM signal with the specified duty cycle is started at the supplied channel.
This technique can be used with a PWM software instance. There's only one thing needed: a new Hertz value for the PWM signal's frequency.
The frequency of the PWM output is changed when this method is used on a PWM object in Python.
The syntax is as follows:
An instance of PWM software can use this technique. One reason is all that is required: the launch of a new cycle of service.
The duty cycle ranges from 0.0 to 100.0. The duty cycle of the PWM signal is changed when this method is called on a PWM instance in Python.
Here is the syntax of the method:
This technique can be used with a software PWM instance. It doesn't need a response. An instance's PWM signal is paused when this method is called on it.
The syntax for this method is:
Congratulations! You have made it to the end of this tutorial. We have seen how PWM is generated in the raspberry pi. We have also seen how to set up our raspberry pi pins with LEDs to be controlled and wrote a python program that controls the output of these pins. The following tutorial will learn how to control a DC motor with Raspberry Pi 4 using Python.
Hi Friends! Hope you’re well today. I welcome you on board. In this post today, I’ll walk you through Cloud Computing Services.
The requirement to process and store data varies from business to business. Some organizations can handle data in on-site data centers. They have a team of experts who handle IT infrastructure and install, maintain and upgrade hardware based on the availability of data. This approach is expensive, no doubt. Some companies, however, don’t accept this model. They prefer cloud computing which is the availability of on-demand IT infrastructure over the internet. This model sets them free from handling and managing on-site data centers, instead, everything is managed and controlled by the cloud service providers. End users only pay for the computing services they use. This IT solution is not only cost-effective but also reliable and secure as your data is managed and stored over the cloud with globally managed data center.
I suggest you read this entire post as I’ll cover cloud computing services and how they can improve the efficiency of any business.
Scroll on.
Cloud services are the availability of software, platform, and infrastructure by the cloud service providers over the internet. Cloud computing services come with the following features:
Cloud computing services are maintained and hosted by cloud service providers. The end users don’t have to purchase or install software or hardware on-site since the service providers host, maintain and purchase the necessary IT infrastructure on their premises.
Service providers offer these services with the pay-as-you-go model which means the end-users only pay for the services and computing resources they use. This is the most economical approach for businesses since they don’t have to install and maintain the entire hardware and software system instead they only pay for the computing resources they use.
Cloud computing offers unlimited storage capacity. The virtual office you create with cloud computing gives you accessibility to almost limitless data to store and manage. This is very difficult to incorporate into traditional data centers since the more storage capacity and bandwidth you need the more hardware and software setup you have to install.
Cloud computing services are mainly divided into three types:
No matter the service model businesses opt for, the cloud service providers host and manage the entire IT infrastructure in their onsite facility. The end users only get only IT resources as a service instead of businesses using them directly.
All three services are different in terms of resource pooling and storage though, they can form a comprehensive model of cloud computing by interacting with each other.
In the following, we’ll discuss these services one by one.
In this service model, the service providers host the software on their own IT system and offer it to organizations based on the subscription fees. This way software is not installed in an individual’s system, instead, users can access the software installed on the cloud data centers over the internet with log-in usernames and passwords.
The services in this SaaS model include calendaring, email, and collaboration. Other business applications that enterprises can get on rent from the service providers include document management, ERP (enterprise resource planning), and CRM (customer relationship management).
Know that cloud software or SaaS is a full web application that requires huge capital investment since cloud service providers offer the full-fledge online app dedicated to the customers of an enterprise. The organizations get these services with a pay-as-you-go plan and more often this type of application or cloud software can be accessed directly from the web browsers without any installation or downloads. The reason, it is commonly called on-demand software, web-based software, or hosted software.
Economical: It works on the pay-as-you-go model which means you only pay for the computing resources you use.
Reduced time: Most SaaS apps can be accessed directly from the web browser. No downloads or installations are required. This means less time is required to run this app which you would otherwise spend on the installation and configuration of apps on an individual system.
Mobility: You can access this cloud software from anywhere in the world.
Automatic Updates: You don’t purchase the entire software. Only the services from that software on rent. This sets you free from manual updates, instead service providers will automatically update the software to avoid any potential threats.
IaaS service is the availability of on-demand IT infrastructure to businesses over the internet. This infrastructure includes operating systems, networks, storage, virtual machines, and servers. The cloud service provider offers this service to the organizations on a pay-as-you-go model.
The IaaS is an ideal solution for small and medium-sized businesses looking for an economical approach for their business growth. This gives them better control over the computing services and removes the need for intricate hardware installation as companies can access this model over the internet.
PaaS is the availability of on-demand IT platforms to businesses over the internet. With PaaS, cloud service providers create an online environment by incorporating multiple technologies including orchestration, containerization, security, routing, management, automation, and application programming interfaces.
Using this service, developers can develop, test, manage and deploy software applications without the need for the underlying infrastructure of the network, storage, servers, and databases required for the development.
Many cloud computing services we already use regularly. Common PaaS services include OpenShift, Apache Stratos, Google App Engine. Similarly Cisco WebEx, DropBox, SalesForce fall under the SaaS service model. And Microsoft Azure, Amazon Web Services, and Cisco Metapod belong to the IaaS service model. End users don’t need hardware and software installation on-premises instead they can access these services with a computer and a strong internet connection.
Know that the cloud computing service models are different from the cloud computing types. The four cloud computing types include Public Cloud, Private Cloud, Hybrid Cloud, and Community Cloud. While cloud computing services, on the other hand, include IaaS, PaaS, and SaaS service models. In the public cloud, services are delivered to the general public. For instance, several organizations can use the public cloud. While in a private cloud, services are delivered to a single organization.
That’s all for today. Hope you’ve enjoyed reading this article. Feel free to reach out in the section below about any questions regarding cloud computing. I’m willing to help in the best way possible. Thank you for reading this post.
We have already mentioned in our previous tutorials that RP2040 or Raspberry Pi Pico supports multiple programming languages like C/C++, Circuit python, MicroPython cross-platform development environments. Raspberry Pi Pico module consists of a built-in UF2 bootloader enabling programs to be loaded by drag and drop and floating-point routines are baked into the chip to achieve ultra-fast performance.
There are multiple development environments to program a Raspberry Pi Pico board like Visual Studio Code, Thonny Python IDE, Arduino IDE etc.
So, in this tutorial, we will learn how to install Thonny Python IDE to program the Raspberry Pi Pico board using Micropython programming language.
Thonny Python IDE (Integrated development environment) is a development tool designed for beginners. The major feature of using Thonny is that it is easy to operate and this development environment also provides a faithful representation of function calls. The Thonny IDE is compatible with Linux, MacOS and Windows OS.
Fig. 1 Download thonny
Fig. 2 Choose Installation Mode
Fig. 3 Accept the agreement
Fig. 4 installation location
Fig. 5 Desktop icon
MicroPython is a programming language that runs directly on embedded hardware, for example, ESP and Raspberry Pi Pico. It is a full implementation of the Python (3) programming language.
Programming Raspberry Pi Pico is a very easy process. Users can program the board by connecting it via USB port, and then just drag and drop the file into Raspberry Pi Pico.
https://www.raspberrypi.com/documentation/microcontrollers/micropython.html
Fig. 6 Download Micropython UF2 file
Fig. 7 Select Interpreter
Fig. 8 MicroPython for Raspberry Pi Pico
Fig. 9 Printing a message with MicroPython (Pi Pico)
So, this concludes the tutorial and the installation procedure of Thonny Python IDE (Windows) for raspberry Pi Pico programming.
In our next tutorial we will discuss how to write a program for raspberry Pi Pico programming to control GPIOs using MicroPython programming language.
Hi Guys! Glad to have you on board. Thank you for clicking this read. In this post today, I’ll walk you through the Types of Internet of Things (IoT).
IoT has been around for a while and has started making the headlines over the past couple of years. Some people experience IoT in their everyday life but are not aware of what it actually is. When physical objects “things” interact with the digital world, IoT is born. In simple words, it’s the network of connected devices integrated with sensors that work to exchange and share data over the internet. It is a rapidly growing technology with more than 18 billion connected IoT devices today and with the inception and boost of 5G technology this figure is expected to touch 125 billion by 2030. Experts say we may witness the stage when everything around us will be a thing in IoT. This is crazy.
I suggest you read this post all the way through as it aims to cover the types of Internet of Things.
Scroll on.
IoT is used to improve efficiency and services, making humans’ lives easy and productive. The connected IoT devices range from simple kitchen appliances and thermostats to heart monitors and cooling systems. And when used in sophisticated industrial tools, IoT can enhance the productivity of the manufacturing and production processes.
The Internet of Things is commonly divided into eight major types:
1: Internet of Things (IoT)
2: Internet of Everything (IoE)
3: Internet of Nano Things (IoNT)
4: Internet of Mobile Things (IoMT)
5: Internet of Mission-Critical Things (IoMT)
6: Industrial Internet of Things (IIoT)
7: Infrastructure Internet of Things
8: Commercial Internet of Things
We’ll discuss each one in the section below.
IoT is a network of things embedded with sensors that connect to the internet for acquiring and sharing data with other connected devices. IoT is applied to make sure which data is important and which is useless to monitor the patterns and find out issues even before they occur. The main purpose of IoT technology is to automate processes, especially that are time-consuming, repetitive, and dangerous.
You might have heard the term “smart home” that has recently soared to popularity and is the main application of the IoT. A smart home is a home with a smart system that is mainly connected with the home appliances to automate certain tasks and can be remotely controlled. From commercial and domestic purposes to industrial and military use, you’ll find IoT everywhere.
Internet of Everything (IoE) is the extension of the Internet of Things. The Internet of Things includes a connected network of things (physical objects) while the Internet of Everything, on the other hand, is about things, processes, data, and people. It covers the Internet for Everyone/Everything.
The IoE plays a key part to monitor and analyze real-time data obtained from a network of thousands of sensors connected to it. This data is then applied to accelerate people-based and automated processes. The IoE is beneficial to support modern business trends and can be incorporated into programs like m-learning and e-learning to allow students to learn new technologies.
Nanotechnology is on the rise. Big tech industries strive to make new devices compact, precise and small that can perform similar tasks to regular electronic devices.
The Internet of Nano Things is a network of Nanodevices connected with the internet to share and acquire information. The presence of Nano components in this technology makes it separable from the general Internet of Things technology.
We are connected through smartphones. We use these devices to ease our lives and improve the way we communicate with each other. The IoMT is mainly geared towards the mobility of things where change occurs in connectivity, context, privacy, and energy availability.
The connectivity identifies how mobile device is connected using connectivity protocol either WiFi, 3G/4G or wired network. The context refers to the current location of the mobile. Energy availability means how a mobile phone is charged and the privacy issue may occur because of the wide use of cell phones thus the mobile phone locations are connected with the human possessors.
The Internet of Mission-Critical Things (IoMT) is used in critical missions like surveillance, critical structure monitoring, search and salvage, border patrol, battleground, etc. In simple words, it’s the use of IoT in battlefield situations or military settings. The main aim of this technology is to accelerate situational awareness, monitor surrounding risks, and improve response time. The main IoMT applications include tanks, planes, connecting ships, drones, and soldiers.
The IoT plays a vital role in industries. This technology is commonly used in industries to automate production and manufacturing processes.
Automation guarantees the accuracy of the processes and removes the possibility of error which is very difficult to attain by using traditional processes and human workforce. Common industries that deploy IIoT include automotive, agriculture, logistics, and healthcare.
Infrastructure IoT is focused on the development of modern infrastructure that uses IoT for maintenance, cost-saving, and operational efficiency. It is concerned to analyze and monitor the operations occurring in rural and urban infrastructures including railway tracks, bridges, and wind farms.
Commercial Internet of Things mainly focuses on the use of IoT in commercial settings including stores, supermarkets, buildings, entertainments venues, healthcare facilities, and hotels. The main purpose of this technology is to improve business conditions, boost customer experience and monitor environmental conditions.
Developing your own IoT device is a no-brainer. There are platforms out there that are open source and offer you the opportunity to create your own IoT devices. Common platforms include Arduino.cc which is open source which means the code is developed to be accessible for the general public – anyone can edit, modify and distribute the code as they like better. And the other platform is Raspberry Pi which comes with a built-in Ethernet port allowing network communications a walk in the park.
That’s all for today. Hope you’ve enjoyed reading this article. If you’re unsure or have any questions regarding IoT, ask me in the section below. I’d love to assist you the best way I can. Thank you for reading this post.