Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Saturday, 11 September 2021

IOT: Designing the Arduino Part of the Face Recognition System

After finalizing the Stock Analyzer project, installing Solar Panels to my house and exploring Quantum Computers, I will continue with my IOT project. 

I am currently able to detect a face using OpenCV on a laptop. The next step will be to migrate that functionality to a headless Raspberry PI that is connected to an Arduino. In this blog post, I will design the Arduino board.

The person in the picture is more similar to James Dean than to Marlon Brando and Audrey Hepburn.
 Training data is very limited, with only 20 pictures of three celebrities, and that causes the identifier to perform poorly
. 

The Arduino Panel
When a user is pressing a button on Arduino, the RPI will take pictures every x seconds. It will try to identify the faces on the last picture. If a face is identified, it will send the corresponding name back to the Arduino. The names will show on the LCD and corresponding LED's will activate. If faces are detected but not identified, an alarm will activate. 

The Piezo element and the red LED to the left are used for alarms.
The button sends a start/stop signal to the connected Raspberry PI computer.
The four LEDs to the right identifies four persons. 


There are three cases:
  • No face is detected on the last picture
  • At least one familiar faces - disable the alarm, if active.
  • No familiar faces - start an alarm.


Saturday, 17 April 2021

RPI: Demo of First Sprint and Sending SMS from 4G Router

In my summer house setup, I have a 4G/Wifi router. The data plan I have allows for some SMS messages to be sent. 

To be able to send SMS messages automatically, I copied a script that I found on a French blog. The code and repo is designed for Jeedom, but it worked on Raspberry PI, too. 

Demo of the First Sprint

With almost all targets met for this sprint, I am able to show a demo of what I've done in my pet project over the very limited spare time I have:

The 4G connection in the summer house is quite slow - 6 Mbit/s. Transmitting a picture of 4 MB will take some 7 seconds, and buffering the video stream will take some time too. When I tried with a better connection, it was a bit quicker.

The Code

I had to create a separate shell script for the stream and SMS setup



NAT Forwarding

The IP number that the 4G router gets is a NAT-ed IP number in the 24 bit block (starting with 10). This makes it hard to access the network from the external internet.

From forum discussions, it seems that I either need to buy a router from the current Internet Service Provider (ISP), or change ISP. Another option would be VPN, but I'll investigate that later in the future.

Next Step

I'll move the remaining task "RPI12: RPI server available from cellular" to the backlog. In the second sprint I'll explore face recognition for openCV. Depending on the output, I'll add more tasks to the sprint later.



Saturday, 13 March 2021

IOT: Data from computer to Arduino

One of the tasks on my first IOT  project anatomy is to send data to the Arduino from Raspberry PI to my Arduino board. 

There is one Arduino feature one needs to consider when sending serial data to Arduino over USB port: Every the serial connection is established, the Arduino is reset. This is a feature that simplifies the process of loading software to the board. 

If a script establishes a serial connection to the Arduino, it takes one second for the board to boot. If the script sends serial data during that time, that data is lost. Further, if the connection is released and reestablished, the board reboots.

My solution to that issue is to wait for the board to boot and to keep the connection alive during the entire session.

The data must be encoded to binary format

The sender script specifies interface, baudrate and timeout and the receiving script sends the incoming string to the display for some seconds. 

And finally, the incoming message is shown on the Arduino LCD.

I'm getting close to completion of the first step of my IOT journey. The remaining tasks are to make the Raspberry Pi available from the external internet, send SMS from the router and to push pictures to the cloud from the Raspberry Pi whenever someone activates the emergency button.

After that, I'll plan the next steps for the IOT project.



Saturday, 30 January 2021

IOT: Data from Arduino to Raspberry PI

In this step, I'll send data from Arduino to Raspberry PI. 

When the user activates the emergency function, a signal will be sent to the RPI that will take a photo and publish on a web server. You can find more information about the traffic lights project here.

Step 1: Connecting Arduino to Raspberry PI

The RPI is connected to a camera module.
A USB cable connects power and serial from the RPI to the Arduino.


The first step is to find the serial port. For the RPI, I've compared the tty ports without and with the Arduino.

The interface /dev/ttyACM0 shows up when I connect the Arduino over USB.

I uploaded a small python script with code that I found on DiyIOt from my Windows computer to my Raspberry PI.

I added a couple of lines to take a photo on the webcam


Step 2: Take a picture, if the emergency button is pressed.
The script checks if the message matches the expected string. If it does, the script will ask the shell to take a photo and save it in /var/www/html/ folder.

When the RPI detects "Switch to Emergency", it captures a JPEG image.
In order to reduce the download time, I've selected a lower resolution than the 3280x2464 that is supported.

Step 3: Publish the image on the web server
The /var/www/html folder is owned by root. This makes it hard to save files there automatically. To resolve this, I've changed the ownership and permissions for that folder. 

A very simple web page that reloads every third second shows the picture. Code and screenshot below:

The updated webpage looks like this:

Now, an event on the Arduino can trigger the RPI to take a photo and show it on an internal web page. The next step will be to send some feedback from RPI to Arduino and to explore video streaming from RPI.





Saturday, 14 November 2020

IOT: Traffic Lights with Arduino

My first IOT project will be a pair of traffic lights that are simulating an intersection.

Iteration 1 - Time Controlled Traffic Lights: 

I've connected six LED's to the outputs of the Arduino Uno. A simple C++ program controls it. The program toggles between the two sets of traffic lights in a sequence that is common in Europe. 

Design and the code that I wrote. I used TinkerCad for making the drawing.

The code and the latest version of the sketch is available on my TinkerCad page.

Step 2 - Emergency Button

The next step is to add an "Emergency Button". Whenever someone presses that button, both sets of traffic lights switches to red and wait until the user presses the button again. Further, the RGB led will blink during that time.   


I only use two input pins for the RGB LED, since that will blink in red or blue only.
I control the brightness of that LED with Pulse Width Modulation.

When the user pushes the button (button state changes to HIGH), the system will either enter or leave the emergency state.

I had some issues with the board leaving the emergency state. The fault was mine - I messed up the output numbers and I sent output to input ports.

The next step will be more complex - I'll add a 16x2 LCD display to the system that will print some useful information to the user.

Saturday, 7 November 2020

IOT: Getting Used with Arduino

 To learn Arduino, I've bought the Arduino Starter Kit. It contains an Arduino board, together with components needed for basic projects and a book that describes the projects. 

The first steps for me is to simply follow the examples in the book. I won't discuss this in detail in the blog, unless I do interesting findings.

Setting Up the Integrated Development Environment

Instead of downloading an Integrated Development Environment for Arduino, I decided to go for the web based option. The compilation of the code is done in the cloud (AWS). A small plugin (Arduino Create) is still needed on my laptop to handle the communication to the board.

Following the Book

From an engineering point of view, this isn't that interesting - but it was an important step. I needed to get my hands dirty and learn how to read the markings on the resistors, understand the difference between the long and short leg of diodes and understand why defensive programming is a good thing.



It is easy to make the first typo.
I did it, and I spent quite a while finding that bug.
If I had compared 7 to "a", the compiler would have complained immediately.

One of my favorite projects was the Crystal Ball, where a tilt sensor is connected to the board together with a Liquid Crystal Display. When the tilt sensor is activated, a random number is sent to the display.
The black box on the right side is the tilt sensor -
a little metallic ball that closes a pair of
connectors when the box tilts.
My Own Project 
Following a book isn't sufficient - I need to do something on my own. The next step is to create a pair of traffic lights with some extra functionality. I'll explore that in the next blog post.

Saturday, 31 October 2020

IOT: A New Project

For the coming year, I will focus on IOT - Internet of Things. I have bought a starter kit for Arduino (a microcontroller with some basic electronic stuff like a motor, diodes, buttons, potentiometers and a LCD display). Together with a Raspberry PI computer that I got as a birthday gift, I have something to start exploring. 
My first project on my own - a simple traffic light.

I'll start with learning the basics - I follow the examples in "Arduino Projects Book" and I'll bring up a Raspberry PI to have basic security and connectivity (no mouse, keyboard or monitor connected).

The long term vision is a remotely controlled vehicle that has a web server and that can take pictures and stream video. Maybe I'll also add some sensors to log temperature. 

The initial project plan looks like this;
Green means done and yellow means "work in progress".
Green means done,
Yellow means "work in progress".
Blue means "not started".

The main obstacle from a fully mobile mini-vehicle is to charge the battery without connecting it manually. I'll look into that later on.