<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>arduino mega Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/arduino-mega/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/arduino-mega/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Sat, 02 Jan 2021 02:15:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>arduino mega Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/arduino-mega/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to use the hallsensor KY-024 with Arduino Code and Wiring</title>
		<link>https://nerd-corner.com/hallsensor-ky-024-arduino-code/</link>
					<comments>https://nerd-corner.com/hallsensor-ky-024-arduino-code/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Tue, 21 Jul 2020 14:09:01 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[arduino mega]]></category>
		<category><![CDATA[Fritzing]]></category>
		<category><![CDATA[hall sensor]]></category>
		<category><![CDATA[hallsensor]]></category>
		<category><![CDATA[KY-024]]></category>
		<category><![CDATA[KY024]]></category>
		<category><![CDATA[Wiring]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=667</guid>

					<description><![CDATA[<p>A Hall sensor can detect magnetic fields and is therefore very suitable in the handicraft area to detect movements. You can often find videos on &#8230; </p>
<p>The post <a href="https://nerd-corner.com/hallsensor-ky-024-arduino-code/">How to use the hallsensor KY-024 with Arduino Code and Wiring</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A Hall sensor can detect magnetic fields and is therefore very suitable in the handicraft area to detect movements. You can often find videos on the Internet in which a Hall sensor KY-024 serves as a tachometer with an Arduino.</p>
<p><em><strong>This might be interesting for you:</strong> <a href="https://nerd-corner.com/hall-sensor-movement-detection/" target="_blank" rel="noopener noreferrer">We built a Hall sensor movement detection wheel</a></em></p>
<p>We have already started small Arduino <a href="https://nerd-corner.com/category/arduino-projects/">projects</a>. Next we want to build a prayer wheel that will light up when it is rotated. For this we will need a Hall sensor.<br />
This post shows a simple example to explain how to connect a Hall sensor to an Arduino and program it so that an LED starts to light up as soon as the Hall sensor KY024 detects a magnetic field.</p>
<h2>List of components</h2>
<ul>
<li>Arudino Mega</li>
<li>Jumper cable</li>
<li>220 Ohm resistor</li>
<li>LED</li>
<li>Magnets</li>
<li>Hall sensor KY-024</li>
</ul>
<p><iframe hcb-fetch-image-from="https://youtu.be/SyzZMWDjQ1w" title="KY-024 Hall Sensor with Arduino code and full user guide!" width="1200" height="675" src="https://www.youtube.com/embed/SyzZMWDjQ1w?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>How does a Hall sensor work or what is the Hall effect?</h2>
<p>When a current-carrying electrical conductor is in a magnetic field, an electrical field builds up. This is perpendicular to the current direction and to the magnetic field and compensates for the Lorentz force which acts on the electrons.</p>
<p>A Hall sensor also provides a signal when the magnetic field in which it is located is constant. This is the advantage compared to a simple coil, which can only determine the derivation of the magnetic field over time.</p>
<h2>The Hall sensor KY-024</h2>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-672 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/KY024.jpg" alt="Hall sensor KY024 KY-024 KY 024 arduino code" width="913" height="755" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/KY024.jpg 914w, https://nerd-corner.com/wp-content/uploads/2020/07/KY024-300x248.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/07/KY024-768x635.jpg 768w" sizes="(max-width: 913px) 100vw, 913px" /></p>
<p>The linear magnetic Hall sensor KY-024 can detect magnetic fields and therefore reacts as soon as you approach it with a magnet. It has a potentiometer with which the sensitivity of the sensor can be set. The KY-024 Hall sensor offers both an analog and a digital output.</p>
<p>The digital output acts as a switch that turns on and off when a magnet is nearby. The analog output, on the other hand, can measure the polarity and relative strength of the magnetic field.</p>
<h2>KY-024 Arduino Wiring</h2>
<p><img decoding="async" class="aligncenter wp-image-670 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine.png" alt="Wiring the KY024 hall sensor to an arduino" width="1913" height="1034" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine.png 1914w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-300x162.png 300w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-1024x554.png 1024w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-768x415.png 768w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-1536x831.png 1536w" sizes="(max-width: 1913px) 100vw, 1913px" /></p>
<p>It is a simple structure that only serves to illustrate the functioning of the KY-024 Hall sensor. Please pay attention to the forward direction of the LED, the kinked end is connected to an Arduino pin and the straight end to GND. Correctly the LED needs a 220 Ohm ballast resistor. However, this can also be neglected for the short duration of use.</p>
<p>Otherwise, connect the GND of the KY-024 to the GND of the Arduino analogous to the <a href="https://fritzing.org/" target="_blank" rel="noopener noreferrer">Fritzing</a> sketch. Connect the analog output A0 of the KY-024 to A0 of the Arduino Mega. Connect the + of the KY-024 to 5V of the Arduino and connect the digital output D0 of the KY-024 to pin 9 of the Arduino. That was the complete wiring.</p>
<h2>Hall sensor KY-024 Arduino Code</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-title="Hallsensor.ino" data-enlighter-theme="beyond" data-enlighter-group="Hallsensor">int LED = 53 ; // LED
int digitalPin = 9; // Hall magnetic sensor input 1 (high) or 0 (low)
int analogPin = A0; // analog Pin also available, but not necessary
int digitalInputValue ; // digital readings
int analogInputValue; // analog readings

void setup ()
{
  pinMode (LED, OUTPUT); 
  pinMode (digitalPin, INPUT); 
  pinMode(analogPin, INPUT); //not necessary, but it is interesting to see the analog values
  Serial.begin(9600);
}

void loop ()
{
  
  digitalInputValue = digitalRead(digitalPin) ; 
  if (digitalInputValue == HIGH) // When magnet is present, digitalInputValue gets 1 (HIGH) and turns LED on
  {
    digitalWrite (LED, HIGH);
    
  }
  else
  {
    
    digitalWrite (LED, LOW);
  }
  
  //Here you can see the analog values of the sensor
  analogInputValue = analogRead(analogPin);
  Serial.println(analogInputValue); // print analog value

  delay(100);
}</pre>
<p>We first define the assignment of the LED (here pin 53), the digital (pin 9) and the analog pin (pin A0) and two variables to read the digital and analog sensor data. The digital pin is sufficient for our purpose of lighting the LED.</p>
<p>The analog pin can actually be neglected. However, since it is useful for this tutorial to show the analog values, the analog pin was nevertheless taken into account in the code.<br />
The respective pin mode is defined in the setup and the digital sensor value of the KY 024 is read in the loop function and, depending on the value, the LED receives the command to light or not. The digital sensor value is either 0 or 1. If you want to, you can use the penultimate 2 lines to display the associated analog values.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-677 size-large zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1024x597.jpg" alt="hallsensor Ky024 arduino code analog data" width="1024" height="597" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1024x597.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-300x175.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-768x447.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1536x895.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data.jpg 1917w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<h2>Download file</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/674/?tmstv=1756250090" rel="nofollow" id="download-link-674" data-redirect="false" >
	Hall sensor KY-024 Arduino code</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/hallsensor-ky-024-arduino-code/">How to use the hallsensor KY-024 with Arduino Code and Wiring</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/hallsensor-ky-024-arduino-code/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
