Friday, May 08, 2015

JAVA Switch Hall sensor with Raspberry Pi

Hello there, 

I am back with my Sunfounder's lesson reviews. This is the post for the lesson review 01 of the "37 modules Sensor Kit for Raspberry Pi Model B". The kit its composed of a good set of sensors at a reasonable price, even though the documentation is really also matching to the reasonable the price. 

However this is the main point about why these kits are a good purchase. They are challenging. You will need to solve issues that emerge when things do not work as expected. This was my experience with the previous kit, the "Sunfounder Super kit for Raspberry Pi Model B". Also in the effort to fully understanding all the technicalities, I started the endeavour of translating all the C code into JAVA for this kits. I will be using the grate Pi4j project, a JAVA wrapper library of the WiringPi project that is used in the C code of the kit's lessons. 


Lets start with lesson 01 about the Hall Effect sensors. This first lesson is using a Switch Hall Module. The C code works just fine, nothing special there.

The main idea of this first lesson is to get familiar with the Hall effect, which was discovered by Edwin hall in 1879. There are a ton of videos in Youtube that explain this effect much better than I will ever do in a blog post. Or a grate document on this subject, if you like to read carefully, is this grate article "Hall effect sensing and application by Honeywell". 

The code is simple and the translation to JAVA is in Ex01_SwitchHall with a jUnit test at Ex01_SwtichHallTest. I just added a slight modification in the loop in order to turn off the led after a short delay. In this way we can test the magnetic field many times with different positions of the magnets around the sensor. 



For full details about how to set up your Raspberry Pi and how to run these exercises please check out my old post Raspberri Pi with Pi4j and Junit testing mockups. Or leave me a comment if you have any issue or question. 

This is all for now, 
Thanks for reading, 

Posted by Marc Andreu.

No comments: